google-chrome-extension - Chrome 扩展将变量传递给在“document.start”上运行的脚本
问题描述
在我的 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
解决方案
推荐阅读
- c# - System.BadImageFormatException:无法加载文件或程序集“PasswordValidator”或其依赖项之一
- opengl-es - 从原始vec4偏移后如何替换texture2D的空白像素?
- ios - iOS swift Facebook AccountKit 自定义
- ios - 如何自定义来自对象库的导航栏
- sql-server - 使用 LDAP 对 SQL Server 数据库的用户进行身份验证?
- python - Pandas - 具有多个条件的 drop_duplicates
- go - 关于接口的方法实现
- python - 读取浮点二进制数据时出现问题
- php - 在 PHP 中使用 GET 和 POST 回显表单数据和操作
- python - 将列表的列分解为多列