Google chrome extension 在浏览器中打开的chrome扩展页能否与背景页通信?
我的一个扩展html页面,在浏览器中打开时需要与后台脚本通信。我尝试了上述方法,但无法将信息从页面发送到后台。我怎么做?我不能在像Google chrome extension 在浏览器中打开的chrome扩展页能否与背景页通信?,google-chrome-extension,Google Chrome Extension,我的一个扩展html页面,在浏览器中打开时需要与后台脚本通信。我尝试了上述方法,但无法将信息从页面发送到后台。我怎么做?我不能在像chrome这样的页面上使用内容脚本-extension://namhfjepbaaecpmpgehfppgnhhgaflne/content/web/viewer.html因此无法使用传统的消息传递您问题中提到的链接适用于扩展包之外的普通网页 如果显示的html文件属于您的扩展包,您可以在页面脚本文件中使用manifest.json允许的所有chrome API 例
chrome这样的页面上使用内容脚本-extension://namhfjepbaaecpmpgehfppgnhhgaflne/content/web/viewer.html
因此无法使用传统的消息传递您问题中提到的链接适用于扩展包之外的普通网页
如果显示的html文件属于您的扩展包,您可以在页面脚本文件中使用manifest.json允许的所有chrome API
例如,要向后台/事件页面发送消息,请使用:
- options.js,链接自options.html
chrome.runtime.sendMessage({text:“Hello”},函数(响应){ 控制台日志(响应); });
- 背景/事件页面
chrome.runtime.onMessage.addListener(函数(消息、发送方、发送响应){ 如果(message.text==“你好”){ sendResponse({text:“Got it”}); } });
- 持久背景页
chrome.extension.getBackgroundPage().someGlobalFunction()
-
chrome.runtime.getBackgroundPage(函数(bg){ bg.someGlobalFunction(); });
..............
您问题中提到的链接适用于扩展包之外的普通网页
如果显示的html文件属于您的扩展包,您可以在页面脚本文件中使用manifest.json允许的所有chrome API
例如,要向后台/事件页面发送消息,请使用:
- options.js,链接自options.html
chrome.runtime.sendMessage({text:“Hello”},函数(响应){ 控制台日志(响应); });
- 背景/事件页面
chrome.runtime.onMessage.addListener(函数(消息、发送方、发送响应){ 如果(message.text==“你好”){ sendResponse({text:“Got it”}); } });
- 持久背景页
chrome.extension.getBackgroundPage().someGlobalFunction()
-
chrome.runtime.getBackgroundPage(函数(bg){ bg.someGlobalFunction(); });
..............
您问题中提到的链接适用于扩展包之外的普通网页
如果显示的html文件属于您的扩展包,您可以在页面脚本文件中使用manifest.json允许的所有chrome API
例如,要向后台/事件页面发送消息,请使用:
- options.js,链接自options.html
chrome.runtime.sendMessage({text:“Hello”},函数(响应){ 控制台日志(响应); });
- 背景/事件页面
chrome.runtime.onMessage.addListener(函数(消息、发送方、发送响应){ 如果(message.text==“你好”){ sendResponse({text:“Got it”}); } });
- 持久背景页
chrome.extension.getBackgroundPage().someGlobalFunction()
-
chrome.runtime.getBackgroundPage(函数(bg){ bg.someGlobalFunction(); });
..............
您问题中提到的链接适用于扩展包之外的普通网页
如果显示的html文件属于您的扩展包,您可以在页面脚本文件中使用manifest.json允许的所有chrome API
例如,要向后台/事件页面发送消息,请使用:
- options.js,链接自options.html
chrome.runtime.sendMessage({text:“Hello”},函数(响应){ 控制台日志(响应); });
- 背景/事件页面
chrome.runtime.onMessage.addListener(函数(消息、发送方、发送响应){ 如果(message.text==“你好”){ sendResponse({text:“Got it”}); } });
- 持久背景页
chrome.extension.getBackgroundPage().someGlobalFunction()
-
chrome.runtime.getBackgroundPage(函数(bg){ bg.someGlobalFunction(); });
..............