Skip to content

Commit b125ead

Browse files
committed
Fix issue that could insta-crash Opera in some launches
It looks like new Opera releases have a UI bug where opening a URL that closes while the tab animation is happening (i.e. instantly) can crash the browser. It reloads and recovers (which is why the previous commit was required) but it would be nice to not do that. If we delay just 1ms this doesn't seem to happen any more, so let's do that.
1 parent 17e6513 commit b125ead

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/hide-warning-server.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import { EPHEMERAL_PORT_RANGE } from './constants';
99
export class HideWarningServer {
1010

1111
constructor(
12-
private config: HtkConfig
12+
private config: HtkConfig,
13+
private options: { delay: number | undefined } = { delay: undefined }
1314
) {}
1415

1516
private server: Mockttp = getLocal();
@@ -37,11 +38,20 @@ export class HideWarningServer {
3738
<script>
3839
const targetUrl = ${JSON.stringify(targetUrl)};
3940
window.open(targetUrl, '_blank');
40-
window.close();
41+
42+
${this.options.delay === undefined
43+
? 'window.close();'
44+
// In some cases (Opera) closing too quickly can make the browser
45+
// crash, so we delay eeeeeever so slightly:
46+
: `setTimeout(() => {
47+
window.close();
48+
}, ${this.options.delay});`
49+
}
50+
4151
</script>
4252
<body>
4353
This page should disappear momentarily. If it doesn't, click
44-
<a href="${targetUrl}">this link</a>
54+
<a href="${targetUrl}">this link</a>.
4555
</body>
4656
</html>
4757
`, { "content-type": "text/html" });

src/interceptors/chromium-based-interceptors.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ abstract class FreshChromiumBasedInterceptor implements Interceptor {
9797
async activate(proxyPort: number, options: { webExtensionEnabled?: boolean } = {}) {
9898
const alreadyActive = this.isActive(proxyPort);
9999

100-
const hideWarningServer = new HideWarningServer(this.config);
100+
const hideWarningServer = new HideWarningServer(this.config, {
101+
delay: this.variantName === 'opera'
102+
? 1
103+
: undefined
104+
});
101105
await hideWarningServer.start('https://amiusing.httptoolkit.tech');
102106

103107
const browserDetails = await getBrowserDetails(this.config.configPath, this.variantName);

0 commit comments

Comments
 (0)