Skip to content

Commit

Permalink
Fix case of scriptlet injection not working about: frames
Browse files Browse the repository at this point in the history
This is an issue in uBO affecting only Chromium-based browsers.

Related feedback:
uBlockOrigin/uBlock-issues#688 (comment)
  • Loading branch information
gorhill committed Dec 18, 2020
1 parent 2867ae1 commit 990cff5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/js/messaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,13 @@ const retrieveContentScriptParameters = function(sender, request) {
response.specificCosmeticFilters =
µb.cosmeticFilteringEngine.retrieveSpecificSelectors(request, response);

if ( µb.canInjectScriptletsNow === false ) {
// https://github.com/uBlockOrigin/uBlock-issues/issues/688#issuecomment-748179731
// For non-network URIs, scriptlet injection is deferred to here. The
// effective URL is available here in `request.url`.
if (
µb.canInjectScriptletsNow === false ||
µb.URI.isNetworkURI(sender.frameURL) === false
) {
response.scriptlets = µb.scriptletFilteringEngine.retrieve(request);
}

Expand Down
1 change: 0 additions & 1 deletion src/js/scriptlet-filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@

api.injectNow = function(details) {
if ( typeof details.frameId !== 'number' ) { return; }
if ( µb.URI.isNetworkURI(details.url) === false ) { return; }
const request = {
tabId: details.tabId,
frameId: details.frameId,
Expand Down
9 changes: 6 additions & 3 deletions src/js/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,10 @@ vAPI.Tabs = class extends vAPI.Tabs {
// properly setup if network requests are fired from within the tab.
// Example: Chromium + case #6 at
// http://raymondhill.net/ublock/popup.html

// https://github.com/uBlockOrigin/uBlock-issues/issues/688#issuecomment-748179731
// For non-network URIs, defer scriptlet injection to content script. The
// reason for this is that we need the effective URL and this information
// is not available at this point.
onNavigation(details) {
super.onNavigation(details);
const µb = µBlock;
Expand All @@ -879,8 +882,8 @@ vAPI.Tabs = class extends vAPI.Tabs {
pageStore.journalAddRootFrame('committed', details.url);
}
}
if ( µb.canInjectScriptletsNow ) {
let pageStore = µb.pageStoreFromTabId(details.tabId);
if ( µb.canInjectScriptletsNow && µb.URI.isNetworkURI(details.url) ) {
const pageStore = µb.pageStoreFromTabId(details.tabId);
if ( pageStore !== null && pageStore.getNetFilteringSwitch() ) {
µb.scriptletFilteringEngine.injectNow(details);
}
Expand Down

0 comments on commit 990cff5

Please sign in to comment.