Skip to content

Commit

Permalink
Fix issue that could insta-crash Opera in some launches
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pimterry committed Feb 22, 2024
1 parent 17e6513 commit b125ead
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/hide-warning-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { EPHEMERAL_PORT_RANGE } from './constants';
export class HideWarningServer {

constructor(
private config: HtkConfig
private config: HtkConfig,
private options: { delay: number | undefined } = { delay: undefined }
) {}

private server: Mockttp = getLocal();
Expand Down Expand Up @@ -37,11 +38,20 @@ export class HideWarningServer {
<script>
const targetUrl = ${JSON.stringify(targetUrl)};
window.open(targetUrl, '_blank');
window.close();
${this.options.delay === undefined
? 'window.close();'
// In some cases (Opera) closing too quickly can make the browser
// crash, so we delay eeeeeever so slightly:
: `setTimeout(() => {
window.close();
}, ${this.options.delay});`
}
</script>
<body>
This page should disappear momentarily. If it doesn't, click
<a href="${targetUrl}">this link</a>
<a href="${targetUrl}">this link</a>.
</body>
</html>
`, { "content-type": "text/html" });
Expand Down
6 changes: 5 additions & 1 deletion src/interceptors/chromium-based-interceptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ abstract class FreshChromiumBasedInterceptor implements Interceptor {
async activate(proxyPort: number, options: { webExtensionEnabled?: boolean } = {}) {
const alreadyActive = this.isActive(proxyPort);

const hideWarningServer = new HideWarningServer(this.config);
const hideWarningServer = new HideWarningServer(this.config, {
delay: this.variantName === 'opera'
? 1
: undefined
});
await hideWarningServer.start('https://amiusing.httptoolkit.tech');

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

0 comments on commit b125ead

Please sign in to comment.