Loading external javascript in google chrome extension

后端 未结 3 1751
暗喜
暗喜 2020-11-28 04:51

I\'m writing a Google Chrome extension which manipulates the current page (basically adds a button).

In my content script, I want to load the Facebook Graph API:

3条回答
  •  旧巷少年郎
    2020-11-28 05:16

    Google Chrome extensions no longer allow injecting external code directly, however you can still download the code with an Ajax call and feed it to the injector as if it was a code block.

    chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
        $.get("http://127.0.0.1:8000/static/plugin/somesite.js", function(result) {
            chrome.tabs.executeScript(tabs[0].id, {code: result});
        }, "text");
    });
    

    source: https://stackoverflow.com/a/36645710/720665

提交回复
热议问题