Scriptlets and scripts are executed too late on website reload or navigation in MV2
Please answer the following questions for yourself before submitting an issue
- [X] Filters were updated before reproducing an issue
- [X] I checked the knowledge base and found no answer
- [X] I checked to make sure that this issue has not already been filed
AdGuard Extension version
4.3.53
Browser version
Chrome 126.0.6478.127
OS version
Windows 10
Ad Blocking
AdGuard Base filter
Privacy
AdGuard Tracking Protection filter, AdGuard URL Tracking filter
Social
AdGuard Social Media filter
Annoyances
AdGuard Annoyances filter
Security
No response
Other
No response
Language-specific
AdGuard Turkish filter
What Stealth Mode options do you have enabled?
No response
Issue Details
First of all, the issue was that pop-ups were appearing on different sites when they were first opened or in certain situations and when I wanted to verify the issue again at same time, I could not reproduce it, so I did a test.
During the testing phase, I only used AdGuard filters in the uBO extension. There seems to be a issue with the AdGuard extension. It can also be noticed that the uBO extension functions faster and more fluidly than the AdGuard extension.
Steps to reproduce:
- Watch compare videos and reproduce the issue.
Expected Behavior
The AdGuard extension does not leak pop-ups.
Actual Behavior
The AdGuard extension leaks pop-ups.
Videos
AdGuard
https://github.com/AdguardTeam/AdguardBrowserExtension/assets/56846906/7aa1571d-e820-4fea-bad0-1d66f58cd751
uBO
https://github.com/AdguardTeam/AdguardBrowserExtension/assets/56846906/d9ce4924-c03b-4d5c-ad04-19329c9049e5
Additional Information
No response
I guess that the problem might be like mentioned here - https://github.com/AdguardTeam/AdguardFilters/issues/182479#issuecomment-2198067258 It looks like that on website reload/navigation sometimes scriptlets are injected too late.
Steps to reproduce:
- Add these rules:
fiddle.jshell.net#%#//scriptlet('set-constant', 'alert', 'noopFunc')
fiddle.jshell.net#%#debugger;
2 Go to - https://jsfiddle.net/1tmha0g8/
Code:
<script>
debugger;
alert(1);
</script>
Alert dialog should be prevented by scriptlet.
On "hard reload", scriptlet is injected in time, but when I click on "Run" button or reload website then almost always rules are injected too late.
Video
https://github.com/AdguardTeam/AdguardBrowserExtension/assets/29142494/71aa6971-4577-44cb-826f-1d7a29dff90b
I have checked old version 4.2.110 and it doesn't occur in this version (I have checked this version, because it was easy to download it from - https://github.com/AdguardTeam/AdguardBrowserExtension/releases, newer versions require to build them).
website reload/navigation
Also happens on first visit too.
Another issue: https://github.com/AdguardTeam/AdguardFilters/issues/182571
Refresh the page (no hard refresh) anti-adblock appears and some rare popups.
Update: This issue a bit different (may not related), take a look this video:
Video
https://github.com/AdguardTeam/AdguardBrowserExtension/assets/56846906/8ca0588a-cebd-44c4-b91e-e0debcc85409
Update 2: After some test, yes it's related. See the video:
Video 2
https://github.com/AdguardTeam/AdguardBrowserExtension/assets/56846906/4742e2ee-f341-4408-b728-ef280ff383dd
Update 3: On this comment, somehow issue has been fixed, see: https://github.com/AdguardTeam/AdguardFilters/issues/182902
Possibility another one: https://github.com/AdguardTeam/AdguardFilters/issues/182802
Possibility another one: AdguardTeam/AdguardFilters#182802
Just tested again 4.1.55 vs 4.3.53 see the video:
Video
https://github.com/AdguardTeam/AdguardBrowserExtension/assets/56846906/01019eac-ff97-4c2b-9fcb-aea9e5c7b1a0
This is a serious issue as end user.
Another issue: https://github.com/AdguardTeam/AdguardFilters/issues/182795
Tested AdGuard extension v4.1.55 vs v4.3.53 see the video:
Video
https://github.com/AdguardTeam/AdguardBrowserExtension/assets/56846906/c301f3ce-4e38-43b7-b9d6-7d6fb9986026
I think different sites and different tests are enough. 😄
Another issue https://github.com/AdguardTeam/AdguardFilters/issues/183315. The rules do not work in the extension 4.3.53. Perhaps they apply too late on the site. However, they work fine in the app.
cety.app#%#//scriptlet('prevent-addEventListener', 'click', 'openPopup')
cety.app#%#//scriptlet('set-constant', 'openPopup', 'noopFunc')
cety.app#%#//scriptlet('remove-node-text', 'script', 'openPopup')
To reproduce this, you should add the exception cety.app#@%#//scriptlet('abort-on-stack-trace', 'document.createElement', 'openPopup').
https://github.com/AdguardTeam/AdguardFilters/issues/183713
javball.com#%#//scriptlet('prevent-fetch', 'pagead2.googlesyndication.com')
javball.com#%#//scriptlet("abort-current-inline-script", "detectAdBlock")
javball.com#%#//scriptlet('abort-on-property-write', 'detectAdBlock')
This is a valid issue. We were trying to be too smart about injecting scriptlets.
Here's what we do now:
- Compute
cosmeticResultin the blocking handler (onBeforeRequestedstarted). - Try injecting it in
onResponseStarted(usually, it fails). - Then go through every lifetime phase of a request and retry injecting.
- Clean up on
onErrorOccurred/onComplete.
We made this too complicated while the proper solution is much, much easier. There's absolutely no need for listening for every lifetime phase, etc.
Just do this:
const injectDoTalogo = (tabId, injectDetails, attemptNumber = 0) => {
console.log(`injecting to ${tabId}, attempt ${attemptNumber}`);
// Use some reasonably big number, 100 or 1000.
if (attemptNumber >= 100) {
console.log('Stop trying, something is very wrong');
}
chrome.tabs.executeScript(tabId, injectDetails, () => {
if (chrome.runtime.lastError) {
injectDoTalogo(tabId, injectDetails, attemptNumber + 1);
} else {
console.log('Now we need to clean up');
}
});
};
chrome.webRequest.onResponseStarted.addListener((details) => {
if (details.type !== 'main_frame') {
return;
}
injectDoTalogo(details.tabId, {
code: 'console.log(new Date().getTime() + " executing scripts!")',
frameId: details.frameId,
runAt: 'document_start',
matchAboutBlank: true,
});
}, { urls: ['<all_urls>'] });
My testing shows that it guarantees the fastest injection.
It also simplifies the code a lot.
You can test it here: https://ameshkov.w3spaces.com/saved-from-Tryit-2024-07-19-ohc1y.html
Add this rule to AG to see the difference: ameshkov.w3spaces.com#%#console.log(${new Date().getTime()} adguard injection);
This issue causes many problems. Like in reporting and even solving the problem.
See: https://github.com/AdguardTeam/AdguardFilters/commit/516850f2ba9148be38a9bbc9b907bbba0d4e3c81
Screenshot
I hope it gets fixed as soon as possible. 😄
Same problem from time to time https://github.com/AdguardTeam/AdguardFilters/issues/188617
https://github.com/AdguardTeam/AdguardFilters/issues/188918#issuecomment-2356323687
Just reporting another case with 4.4.49 on Chrome. For https://github.com/uBlockOrigin/uAssets/issues/27316 uxsyplayer8d1f6edba292.click##+js(set, document.referrer, '') works reliably with uBO, but uxsyplayer8d1f6edba292.click#%#//scriptlet('set-constant', 'document.referrer', '') with AG fails on reload (almost 100%).
fix is to be available in v5.1.62
Just reporting another case with 4.4.49 on Chrome. For uBlockOrigin/uAssets#27316
uxsyplayer8d1f6edba292.click##+js(set, document.referrer, '')works reliably with uBO, butuxsyplayer8d1f6edba292.click#%#//scriptlet('set-constant', 'document.referrer', '')with AG fails on reload (almost 100%).
Was the "Filtering log" window open during the test? Because I can only reproduce this issue when the "Filtering log" window is open, and I noticed that it slows down site navigation and causes blocked ads elements to briefly appear during page refresh before disappearing.
Edit: Oh it's related to v4.4.49. my comment is for, AdGuard AdBlocker MV2 v5.1.70 😄
Tested on 5.1.70, uxsyplayer1a09531928c5.click#%#//scriptlet('set-constant', 'document.referrer', '') rather breaks the player, but I see this both with the logger opened and not opened.
Tested on 5.1.70,
uxsyplayer1a09531928c5.click#%#//scriptlet('set-constant', 'document.referrer', '')rather breaks the player, but I see this both with the logger opened and not opened.
Are you encountering an error as shown in the screenshot?
Screenshot
If so, this is likely due to the site's link tabs being offline. If not, how does it look on your side? On my end, there is no issue with the 'active' link tabs with this filter rule. 🤔
Yeah, exactly that.
Yeah, exactly that.
In the 7/24 tab, the first two tab are offline, the 3rd and 4th are online, try it if you want.
AdGuard AdBlocker MV2 v5.1.79
Another case: https://github.com/AdguardTeam/AdguardFilters/issues/204450#issuecomment-2847260628
With Filtering logs enabled, on a site that uses tab sections where each tab loads a different video player, switching tabs results in executed too late of the scriptlet filter rule.
@kodiakhub I couldn't reproduce the issue with player with or without Filtering log enabled on 5.1/5.0.
But we could reproduce this issue https://github.com/AdguardTeam/AdguardBrowserExtension/issues/3178 only with the Filtering log or Help with the development of AdGuard filters feature enabled and the fix should be available in 5.2.
If the issue is still relevant please wait until we release 5.2 version and check if the problem persists there.
If the issue is still relevant please wait until we release 5.2 version and check if the problem persists there.
Okay, I'll wait for 5.2. If it's still happening, I'll upload a video. 😄