How to get permission to access my own extension resources (specific page)?

Due to recent changes to the Chrome API, my plugin throws this error:

Error during tabs.executeScript: Cannot access the contents of the URL "Chrome extension: //ecfgljdfndkhhbmhcnelbpnhkflgiokp/cm_signature_editor.html". The expansion manifest must request permission to access this host.

It has never been so. Now I am wondering how to get the chrome extension url into the manifest file:

I know that I can get the url or resource in my extension, for example:

chrome.extension.getURL('/manifest.json')

But I do not know how this can work in the manifest file.

Is there any other way to make this code work?

 chrome.tabs.executeScript(null, {code:function_to_execute}, function() { // callback }); 

Interestingly, even when I hardcode the chrome URL, it doesn't work (I get the same error)

 "permissions" : [ "tabs", "contextMenus", "chrome-extension://ecfgljdfndkhhbmhcnelbpnhkflgiokp/*" ], 
+6
source share
3 answers

I think you cannot enter a script on the extension page this way. You should include the script on the page by simply writing it to your HTML extension file. And do the communication between extension pages using chrome.extension.sendRequest and chrome.extension.onRequest

+1
source

Using chrome.extension.getViews() can be useful.

+1
source

Maybe I know what the problem is :) There are two ways to paste script content into chrome.tabs.executeScript :

  • line of code - works similarly to eval
  • filename - therefore, if you want to execute the js file that you have in your extension directory, just pass its name {file: 'js/script.js'}

In addition, you must add the correct site host in the manifest permission field, for example. if you want to execute the content script in http://example.com/page.html add example.com host

-1
source

Source: https://habr.com/ru/post/912242/


All Articles