google-chrome-extension

addEventListener not triggering when used in a chrome extension

瘦欲@ 提交于 2020-04-08 10:32:15
问题 I'm trying to make a chrome extension that will search different cache databases for a given page. However, it's not working as I expect it to. <!DOCTYPE HTML> <html> <head> <script type="text/javascript"> var x; var img = document.getElementsByTagName("img"); for(x in img) { img[x].addEventListener('click',openPage, false); } function openPage(event) { alert("clicked"); var e = event.target; switch(e.alt) { case "WayBack Machine": chrome.tabs.update(tab.id, { url: "http://wayback.archive.org

addEventListener not triggering when used in a chrome extension

╄→гoц情女王★ 提交于 2020-04-08 10:31:30
问题 I'm trying to make a chrome extension that will search different cache databases for a given page. However, it's not working as I expect it to. <!DOCTYPE HTML> <html> <head> <script type="text/javascript"> var x; var img = document.getElementsByTagName("img"); for(x in img) { img[x].addEventListener('click',openPage, false); } function openPage(event) { alert("clicked"); var e = event.target; switch(e.alt) { case "WayBack Machine": chrome.tabs.update(tab.id, { url: "http://wayback.archive.org

chrome.runtime.onMessage response with async await

心不动则不痛 提交于 2020-04-07 18:44:28
问题 I want to use async await in an onMessage listener: chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) =>{ var key = await getKey(); sendResponse(key); }); However I get undefined when I send a message. From the documentation for chrome.runtime.onMessage.addListener: This function becomes invalid when the event listener returns, unless you return true from the event listener to indicate you wish to send a response asynchronously (this will keep the message channel open

Extension manifest must request permission to access this host

橙三吉。 提交于 2020-04-04 03:34:59
问题 I am trying to append a div to page of current active tab. However I am getting this error: Error during tabs.executeScript: Cannot access contents of url .... Extension manifest must request permission to access this host. My Code: (show_loader.js) var dv = document.createElement('div'); dv.id = 'myid'; dv.innerHTML = 'test'; document.body.appendChild(dv); However when I put this code: document.body.style.backgroundColor = 'green'; It works as expected and background color of current tab is

Extension manifest must request permission to access this host

守給你的承諾、 提交于 2020-04-04 03:34:53
问题 I am trying to append a div to page of current active tab. However I am getting this error: Error during tabs.executeScript: Cannot access contents of url .... Extension manifest must request permission to access this host. My Code: (show_loader.js) var dv = document.createElement('div'); dv.id = 'myid'; dv.innerHTML = 'test'; document.body.appendChild(dv); However when I put this code: document.body.style.backgroundColor = 'green'; It works as expected and background color of current tab is

Extension manifest must request permission to access this host

感情迁移 提交于 2020-04-04 03:34:49
问题 I am trying to append a div to page of current active tab. However I am getting this error: Error during tabs.executeScript: Cannot access contents of url .... Extension manifest must request permission to access this host. My Code: (show_loader.js) var dv = document.createElement('div'); dv.id = 'myid'; dv.innerHTML = 'test'; document.body.appendChild(dv); However when I put this code: document.body.style.backgroundColor = 'green'; It works as expected and background color of current tab is

Why is the response body empty (0 bytes on network tab) for this request? Is it to do with this being an extension?

心不动则不痛 提交于 2020-03-26 03:58:42
问题 When I use the fetch API (Or xmlhttprequest) I get a 0 byte response. Here is a sample of my code: fetch("https://myurl", { method: "POST", headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({content: content}) }).then(function(res){ return res.text()}).then(function(res){ return cb(res);}); In the network tab, and in the console.log(res) in the callback, the response is empty. I should note that the response is including a CORS response

How to execute my content script on a newly opened chrome tab?

♀尐吖头ヾ 提交于 2020-03-24 07:13:20
问题 I am calling a Chrome extension from a web portal to open a URL in a new tab, and on the newly opened tab I want to perform executeScript : manifest.json "externally_connectable": { "matches": ["http://localhost:3000/*"] }, "permissions": ["tabs", "http://*/*", "https://*/*"] background.js // listen to webportal chrome.runtime.onMessageExternal.addListener( function(request, sender, sendResponse) { a = chrome.tabs.create({ url: request.openUrlInEditor }); chrome.tabs.insertCSS(a.id, { file:

Chrome Extension Shortcuts

旧城冷巷雨未停 提交于 2020-03-23 12:09:07
问题 I'm writing a simple extension that has a .js file with only 2 functions and a listener (which only writes to Console - but I can't see it and not sure it catches anything). I'd like to have shortcuts assigned, let's say Ctrl+Shift+1 and Ctrl+Shift+2 to both functions. I'm not exactly sure how to do it, and if it's possible. The data I've been able to gather online didn't cover what I'm looking for. I have no need for html popup. All I want is to press the shortcut and have the correspondent

Chrome addon is randomly sending trash to my c++ native host application

给你一囗甜甜゛ 提交于 2020-03-23 08:22:32
问题 I'm trying to write a simple parental control app for my university project, but I'm a newbie in browser addons. I want to use Chrome addon to send hosts viewed by the user in real-time to Qt app, which will analyze the user behavior. The problem is, that sometimes chrome's sending a correct host, another time it's sending trash with an empty string or enormously long message, which my Qt app filter. But these 'wrong' messages are sent in an endless loop, and to make it working again, I have