JSFiddle - React, Tailwind, and code Playground
CSS
//content_script.js
console.log(scriptOptions.param3);
//dla 'przyklad' loguje przyklad , dla zmiennej:
VM962:1 Uncaught SyntaxError: Unexpected identifier
content_script.js:1 Uncaught ReferenceError: scriptOptions is not defined
at content_script.js:1
JavaScript
//popup.js
function injectTheScript() {
var refresh = $('#refresh').val();
var category = $('#select').val();
var name = $('#name').val();
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
// query the active tab, which will be only one tab
//and inject the script in it
chrome.tabs.executeScript(tabs[0].id, {
code: "var scriptOptions = {param1:"+refresh+",param2:"+category+", param3:'przyklad'};"//dziala
code: "var scriptOptions = {param1:"+refresh+",param2:"+category+", param3:"+name+"};"//nie dziala
}, function(){
chrome.tabs.executeScript(tabs[0].id, {file: "content_script.js"}, function(){
//all injected
});
});
});
}
document.getElementById('button').addEventListener('click', injectTheScript);