Tag: firefox webextensions

从浏览器扩展调用网页JavaScript方法

我正在使用webExtensions开发一个firefox扩展,它可以帮助我轻松完成下面的场景。 我必须点击网站上大约50-60个按钮来更新任务状态。 单击此按钮,网页将调用网页的updTask(id) JavaScript函数,然后进行Web服务调用以更新任务。 我无法使用以下代码从我的内容脚本中执行此操作: manifest.json : “permissions”: [ “activeTab”, “cross-domain-content”: [“http://workdomain.com/”,”http://workdomain.org/”,”http://www.workdomain.com/”,”http://www.workdomain.org/”] ] 内容脚本代码: function taskUpdate(request, sender, sendResponse) { console.log(request.start + ‘inside task update’); updateTask(45878); chrome.runtime.onMessage.removeListener(taskUpdate); } function updateTask(id) { //TODO: code to get all buttons and task id’s updTask(id); // Not working } 插件脚本: document.addEventListener(“click”, function(e) { if (e.target.classList.contains(“startButton”)) { chrome.tabs.executeScript(null, { file: “/content_scripts/taskUpdate.js” […]

如何仅在用户更改URL时触发事件?

我正在使用Chrome扩展程序,我想检测用户输入url的时间。 我知道: chrome.tabs.onUpdated.addListener(eventLisenerObj.onUpdated); 但是,只要URL被更改(例如,页面自动重新加载,或用户点击链接等),就会调用它。 我希望能够确定只有用户输入URL才能更改URL。