В моем файле 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