Hey,
we're looking into an option to use offscreen documents to perform some dom scraping of a website loaded in an iframe.
As far as I understand, we can use the following code to open the document:
chrome.offscreen.createDocument({
url: 'offscreen.html',
reasons: [chrome.offscreen.Reason.DOM_SCRAPING],
justification: 'To do smth',
});
And this works fine.
Then we create an iframe with the URL of a website we want to scrap. The website however uses X-Frame-Options: Sameorigin so it doesn't load:
"Refused to display 'https://www.website.com/' in a frame because it set 'X-Frame-Options' to 'sameorigin'."So we need to get rid of that header. We have MV3 extension, but we haven't used blocking web requests so far. AFAIU we would need a new permission to remove that header from the response: declarativeNetRequest (and its blocking version). The problem is that the permission will trigger a warning and users really don't like that.
I tried to use he following code:
chrome.webRequest.onHeadersReceived.addListener(
data => {
if (data.url.includes('website.com')) {
const headers = data.responseHeaders ?? [];
const withNoXFrameOptions = headers.filter(h => h.name !== 'x-frame-options');
return { responseHeaders: withNoXFrameOptions };
}
},
options,
['extraHeaders', 'responseHeaders']
);
const options: RequestFilter = {
urls: ['<all_urls>'],
types: ['xmlhttprequest', 'main_frame', 'sub_frame'],
};It doesn't work. The listener is triggered but it doesn't override the headers. I believe it's because we would need the "blocking" option specified, which requires the blocking webRequest permission, and this permission is not available in MV3.
Is there any other option to override that header or load a website in an iframe in offscreen doc, without causing warnings (new permissions)? Currently we have "["storage", "alarms", "webRequest", "scripting", "offscreen"]" and broad host permission because of the content script settings.