I am working on Chrome extension, which need to get access to document.styleSheets
cssRules
. It works fine with some websites, e.g. w3school, but others don't, like stackoverflow.
I am getting an error:
Failed to read the 'cssRules' property from 'CSSStyleSheet': Cannot access rules
I know about CORS policy for Chrome browser but I am embeding script into the page using this approach:
chrome.tabs.executeScript(tabId, {file:'script.js'});
Seems to me the problem is caused because file with styles are downloaded from other domain, but for me isn't clear why I am getting the error, the script is embedded on the page and code executes in scope of website. Could you please clarify, what is the problem?
Stuff with chrome.debugger also not works:
chrome.debugger.attach(debuggeeId, "1.3", () => {
chrome.debugger.sendCommand(debuggeeId, "Page.enable", null, (r) => {
chrome.debugger.sendCommand(debuggeeId, "Page.getResourceTree", null, (res) => {
const cssResources = getCSSResources(res.frameTree.resources);
for(let url of cssResources) {
chrome.debugger.sendCommand(debuggeeId, "Page.getResourceContent", {frameId: toString(tabId), url: url}, (resp) => {
console.log(resp)
})
}
})
})
})