While creating a Google Chrome extension, I have code that must remain in a separate javascript file:
separate.js
-----------
var x = "some dynamic value";
var y = "another dynamic value";
return x;
I would like to get the value of x from this code into a code included in my background page:
background.html
-----------
<!DOCTYPE html>
<html>
<head><script src="code.js"></script></head>
</html>
_
code.js
-----------
chrome.tabs.executeScript(null, {file:"separate.js"}, function() {});
How do I go about retrieving a variable set in separate.js (say, y)? Is there a way to use executeScript() to get the return value of a script?
At your
code.js(injected by your extension), make use ofchrome.extension.sendRequest:At
separate.js(atbackground.html), usechrome.extension.onRequest: