Skip to content

Commit

Permalink
Create synthetic event for new windows created from external application
Browse files Browse the repository at this point in the history
Related discussion:
- uBlockOrigin/uAssets#10323 (comment)

Synthesize a onCreatedNavigationTarget event for new browser windows
created as a result of an external application triggering a navigation
event.
  • Loading branch information
gorhill committed Dec 14, 2021
1 parent 01f87e9 commit 89e6788
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions platform/chromium/vapi-background-ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
// https://github.com/uBlockOrigin/uBlock-issues/issues/1659
// Chromium fails to dispatch onCreatedNavigationTarget() events sometimes,
// so we synthetize these missing events when this happens.
// https://github.com/uBlockOrigin/uAssets/issues/10323
// Also mind whether the new tab is launched from an external application.

vAPI.Tabs = class extends vAPI.Tabs {
constructor() {
Expand Down Expand Up @@ -65,12 +67,11 @@ vAPI.Tabs = class extends vAPI.Tabs {
synthesizeNavigationTargetEvent(details) {
if ( this.tabIds.has(details.tabId) === false ) { return; }
this.tabIds.delete(details.tabId);
if (
Array.isArray(details.transitionQualifiers) === false ||
details.transitionQualifiers.includes('client_redirect') === false
) {
return;
}
const isClientRedirect =
Array.isArray(details.transitionQualifiers) &&
details.transitionQualifiers.includes('client_redirect');
const isStartPage = details.transitionType === 'start_page';
if ( isClientRedirect === false && isStartPage === false ) { return; }
this.onCreatedNavigationTargetHandler({
tabId: details.tabId,
sourceTabId: details.tabId,
Expand Down

0 comments on commit 89e6788

Please sign in to comment.