My extension using webRequest doesn't work on Vivaldi
-
Hi everyone,
I'm developing an extension that uses the webRequest object and I'm using the onCompleted event and attaching an event listener to it to make some javascript action to happen (in my case, scrolling the page below), problem is that I'm detecting when the main page URL through this way, and relying on the details object that is passed to the callback of the
chrome.webRequest.onCompleted.addListener
.
The question is that with the other chrome-based browsers the main page thetype
field has the valuemain_frame
when I want to grab the main page URL and discard all the other URLS from the components of the page. The problem with Vivaldi is that I don't see ever thetype
ofmain_frame
on thedetails
argument but instead I see lot of axmlhttprequest
passing through. I don't know of this is somehow related with the modifications you made (see https://vivaldi.com/blog/manifest-v3-webrequest-and-ad-blockers/) to avoid the adblocker to stop working with the migration to the extensions manifest v3.
The question is that I don't want to have to modify my code just to make my extension work just for Vivaldi, which is my browser of chossing from 10 years ago to now.Thanks for your attention,
-
@digfish Won't be possible to check for testers if you don't provide a link to your extension.
By the way, Vivaldi doesn't do extensive modifications to chromium code. The link is just a memo about the imminent phasing out of manifest V2 extensions and a possible alternative (which is the vivaldi blocker).
If your extension is manifest V2 might be already affected but can be overcome (at the moment)
https://forum.vivaldi.net/topic/79579/manifest-v3-webrequest-and-ad-blockers/171?_=1716787493337
-
@Hadden89 hi, thanks for your quick reply. My extension is not available, since it's in a very early stage of development.
But I'll try to explain what I'm to trying to acomplish with my extension: store the progress of reading a webpage as progress value as an extra parameter in the query string of the URL that it's stored in a bookmark. The progress is the value of current position in the vertical scroll of a lengthy web page expressed as a percentage. When opening that URL, I need an hook that detects the presence of thatprogress
parameter in the URL and I'm trying to do that using the onComplete event of the WebRequest object. TheonCompleted
fires and gives me adetails
argument in the callback that I can inspect, and I can see atype
field in that object argument that identifies the nature of the content being loaded into the browser. I just want the main document webpage which is identified by themain_frame
value. The problem is that Edge and Chromium gives the type with that value but Vivaldi gives me anxmlhttprequest
instead.
And so this snippet of code:chrome.webRequest.onCompleted.addListener( function (details) { //if (details.type == 'xmlhttprequest') { return } console.log('onCompleted', details.type,details.url); if (details.type == 'main_frame') { console.log('url', details.url); console.log("Request completed:", details); // extract the query string from the URL var queryString = details.url.split('?')[1]; // parse the query string into a dictionary var query = new URLSearchParams(queryString); // show all the fields console.log(query.get('progress')); chrome.scripting.executeScript({ target: { tabId: details.tabId, allFrames: true }, function: gotoscroll , args: [query.get('progress')], }); function gotoscroll(pos) { console.log('scrolling to', pos); bodyHeight = document.body.scrollHeight; window.scrollTo(0, pos / 100 * bodyHeight); } } } , { urls: ["<all_urls>"] } );
produces this in the browser console on Edge:
and this on Vivaldi:
Can you now understand the difference ?
Thanks again for your patience, -
@digfish Problem solved ! Just use
chrome.tabs.onUpdated
instead ofchrome.WebRequested.onCompleted
! It gives the main page URL and the tab id, all that I just need ! Don't need to mess with WebRequest anymore !