Расширение Chrome передает переменную в скрипт, который запускается на «document.start» - PullRequest
0 голосов
/ 12 марта 2019

В моем файле manifest.json

"content_scripts": [
    {
      "matches": [ "https://*/*", "http://*/*" ],
      "run_at": "document_start",
      "all_frames": true,
      "match_about_blank": true,
      "js": [ "run_on_every_page.js" ]
    }

В файле run_on_every_page.js

var yourCustomJavaScriptCode = 'document.pageVariable={I_want_variable_from background.js_to_be_inserted_here};';
var script = document.createElement('script');
var code = document.createTextNode('(function() {' + yourCustomJavaScriptCode+ '})();');
script.appendChild(code);
document.documentElement.appendChild(script);

Как вставить переменную из background.js в файл "I_want_variable_from background.js_to_be_inserted_here"?

Background.js:

var myVariable=Math.random();//Dynamic variable that changes based on user activity
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...