Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension

前端 未结 3 1008
感情败类
感情败类 2020-12-14 06:56

I have tried many ways( all documented procedures)to inject script into a specific page upon checking URL at onUpdated.addListener. Finally the below code with \'executescri

相关标签:
3条回答
  • 2020-12-14 07:26

    Many will land up on this page for this error because they have not included their images/web resources in the manifest.json file. The link to the api documentation is helpful, so sharing it: web resource in manifest

    0 讨论(0)
  • 2020-12-14 07:29

    EDIT:

    This is working version where combination of web_accessible_resources and Injection is used

    manifest.json

    {
    "name":"Off Screen Tabs Demo",
    "description":"This demonstrates Off Screen Tabs API",
    "manifest_version":2,
    "version":"1",
    "permissions":["tabs","<all_urls>"],
    "browser_action":{
        "default_icon":"screen.png",
        "default_popup":"popup.html"
    },
     "web_accessible_resources": ["js/LeoScript.js"] ,
     "permissions":["tabs","<all_urls>"]
    }
    

    LeoScript.js

    alert("Injected..");
    

    popup.html

    <html>
    <head>
    <script src="popup.js"></script>
    </head>
    <body>
    </body>
    </html>
    

    popup.js*

    document.addEventListener("DOMContentLoaded",function (){
        chrome.tabs.executeScript( {"file": "js/LeoScript.js"});
    });
    

    Let me know if you still have problem in getting it running

    0 讨论(0)
  • 2020-12-14 07:41

    UPDATE: Finally figured out your problem. In eventPage.js, you tried to inject js/Leoscript.js, which is NOT whitelisted, instead of js/LeoScript.js (with a capital 'S'), which is whitelisted. Note that URLs are case-sensitive!

    chrome.tabs.executeScript(tabId, {file: 'js/LeoScript.js'});
    

    LeoScript.js:

    alert('injected');
    document.getElementById('username').value='aaaaaaa';
    
    0 讨论(0)
提交回复
热议问题