消息传递在chrome扩展中不起作用
Message Passing is not working in chrome extention
我尝试将消息从我的Default_popup.js传递到内容脚本,当它在内容脚本端接收时,然后尝试将数据保存在chrome存储上。但我的代码工作不正常。
此代码已被处理了2-3次。但现在它不起作用了。
manifest.json
{
"manifest_version": 2,
"name": "Test",
"description": "Automated Test Tool.",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "Default_Popup.html"
},
"content_scripts": [{
"matches":["http://*/*","https://*/*"],
"js":["myscript.js"] }
],
"background":{
"scripts":["background.js"]
},
"permissions":[
"storage",
"notifications",
"tabs",
"http://*/",
"https://*/"
]
}
Popup.js
chrome.tabs.getSelected(null, function (tab) {
var Jour = {};
Jour.FromStation = $('#txtFromStation').val();
Jour.ToStation = $('#txtToStation').val();
Jour.JourneyDate = $('#datepicker').val();
chrome.tabs.sendRequest(tab.id, { JourneyDetails: Jour }, function handler(response) {
alert("Inside Client = " + "Done");
});
});
myscript.js//内容脚本
window.onload = function () {
chrome.extension.onRequest.addListener(
function (request, sender, sendResponse) {
alert('request.JourneyDetails.FromStation');
alert(request.JourneyDetails.FromStation);
var Jour = {};
Jour.FromStation = request.FromStation;
Jour.ToStation = request.ToStation;
Jour.JourneyDate = request.JourneyDate;
chrome.storage.sync.set({ JourneyDetails: Jour }, function () {
console.log('Setting Saved')
});
//sendResponse({ counter2: "5" });
}
);
}
chrome.tabs.getSelected()
已弃用,是否尝试使用chrome.tabs.query()
?https://developer.chrome.com/extensions/tabs#method-getSelectedchrome.tabs.sendRequest()
和chrome.extension.onRequest()
已弃用,是否尝试使用chrome.tabs.sendMessage()
和chrome.runtime.onMessage()
?https://developer.chrome.com/extensions/tabs#method-sendRequest,https://developer.chrome.com/extensions/extension#event-onRequest- 是否在Default_Popup.html中包含jQuery?你看到的错误是什么
- Default_Popup.html中id为
$('#txtFromStation'), $('#txtToStation'), $('#datepicker')
的元素吗?如果您可以发布Default_Popup.html的内容,那将很有帮助
相关文章:
- o数据扩展查询在SystemUserRolesSet上不起作用
- 正在处理在chrome扩展中不起作用的js
- 为什么这个扩展方法不起作用
- 为什么我的谷歌浏览器扩展程序在谷歌浏览器版本 41.0.2272.89 中不起作用
- Chrome 扩展程序权限不起作用
- Chrome 扩展 cookies.getAll 不起作用
- List.JS 在通过 Chrome 扩展程序注入时不起作用
- 设置Sails js视图扩展不'不起作用
- 使用jQuery的Chrome扩展不起作用
- chrome扩展名“sendResponse”不起作用
- 基本的谷歌chrome扩展消息传递不起作用
- $(document).click()在chrome扩展中不起作用
- Javascript在Google Chrome扩展的选项页中不起作用
- 在chrome扩展的弹出窗口中,警报不起作用
- firefox扩展对$.ajax的调用不起作用
- I'我试图制作一个chrome查找和替换扩展,但它赢了;不起作用
- chrome扩展弹出相同的选项卡仍然不起作用
- Javascript按钮单击在Chrome扩展弹出窗口中不起作用
- Google Chrome扩展:setAttribute没有'不起作用
- 验证不起作用(扩展)