google-chrome-extension

Chrome content scripts aren't working: DOMContentLoaded listener does not execute

余生长醉 提交于 2019-12-17 20:05:11
问题 I am trying to code extension that corrects misspellings on 1 forum. I am trying to access <p> tag, with content script, but it doesn't change anything (using the code below): document.addEventListener("DOMContentLoaded", function() { document.getElementsByTagName("P")[4].innerHTML = "correct_word"; }); It doesn't change anything when added as an extension, apparently if I wget the page, and put the script there, all works. Any thoughts? My manifest.json file: { "manifest_version": 2, "name":

DOM Exception 12 for window.postMessage

╄→尐↘猪︶ㄣ 提交于 2019-12-17 20:03:09
问题 I'm learning to build Chrome Extensions, and I'm trying to follow one of the instructions in the official Guide here. What I am trying to accomplish is: background.js shows page action for targetted URLs. Page action executes a script when clicked. Executed script injects javascript on page. So far, so good! I use the following script to inject into the page. var injectJS = function(url, cb) { var h = document.getElementsByTagName('head')[0], s = document.createElement('script'); s.type =

Google chrome extension: how to inject script immediately after page reload?

爷,独闯天下 提交于 2019-12-17 20:01:30
问题 I have a background script that periodically reloads the current tab. var code = 'window.location.reload();'; chrome.tabs.executeScript(my_active_tab, {code: code}); After each page reload, immediately I want to inject another script. chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab){ if (changeInfo.status == 'complete') { chrome.tabs.executeScript(tabId, { file: "my_script.js" }); } }); Above is the code I have at the moment. The thing is, it works but it is too slow,

CHROME WebRequest APIs example error: “onBeforeRequest” can only be used in extension processes

假装没事ソ 提交于 2019-12-17 19:51:43
问题 I try to test a example of WebRequest APIs, but throw error: "onBeforeRequest" can only be used in extension processes. manifest.json: { "name": "example", "version": "1.0", "permissions": [ "experimental", "http://*/*", "https://*/*" ], "content_scripts": [ { "js": [ "foo.js" ], "matches": [ "http://*/*", "https://*/*" ], "run_at": "document_start" } ] } foo.js is exactly the example 1 回答1: Chrome extension functions (which includes the webRequest API) cannot be used in content scripts ( foo

Execute a program from a Chrome Extension

大城市里の小女人 提交于 2019-12-17 18:55:24
问题 The Google Chrome NPAPI is being phased out. Without using NPAPI, is there any way to allow an extension to execute a command on the local system? 回答1: There is chrome.runtime.sendNativeMessage which can be used to send a message to a native application and chrome.runtime.connectNative which allows for a more persistent connection. So, you can't directly execute a command, but you can have a native app do it for you. You can find more info on Native Messaging in the docs . 来源: https:/

Native Messaging Chrome

谁都会走 提交于 2019-12-17 18:43:27
问题 I am trying to get Native Messaging between my chrome extension and my c# application. The javascript works fine, but I am getting this error: Error when communicating with the native messaging host. The application does get launched along with the extension, as I saw from Task Manager. Here is my c# code. private static string OpenStandardStreamIn() { //// We need to read first 4 bytes for length information Stream stdin = Console.OpenStandardInput(); int length = 0; byte[] bytes = new byte

How to get errors stack trace in Chrome extension content script?

◇◆丶佛笑我妖孽 提交于 2019-12-17 18:42:06
问题 There is a Google Chrome extension with content script that handles JS errors occured on all tabs pages. But the problem is that no one of usual methods of getting errors stack trace does not work. For example, there is a code in content script of Chrome extension: window.addEventListener('error', function(event) { console.log(event.error.stack); // event.error will be null }, false); If I call this code inside web page, so event.error will contains Error object with stack property. Same

chrome.runtime.sendMessage not working as expected

左心房为你撑大大i 提交于 2019-12-17 18:39:27
问题 I am writing a Chrome plugin with a content script and a background script, and I am trying to make the two communicate. In my content script, I am doing chrome.runtime.sendMessage({greeting: "hello"}, function(response) { console.log(response.farewell); }); and in my background script, I am doing chrome.runtime.onMessage.addListener( function(request, sender, sendResponse) { console.log(sender.tab ? "from a content script:" + sender.tab.url : "from the extension"); if (request.greeting ==

chrome extension insert content script on browser action

做~自己de王妃 提交于 2019-12-17 18:35:10
问题 I am trying to make basically an element highlighter chrome extension. Workflow: - click on browser icon - click on the page - hightlight the element clicked I am having troubles in running content scripts upon browser action using manifest_version:2 When I inspect the popup that appears it says: Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' chrome-extension-resource:" (popup.html:5). Which is where the inline script

chrome.tabs.executeScript: Cannot access a chrome:// URL [duplicate]

喜欢而已 提交于 2019-12-17 18:28:14
问题 This question already has answers here : Can you access chrome:// pages from an extension? (3 answers) Closed 5 years ago . I am pretty new to chrome extension development. The issue is not with accessing the chrome:// url I do not want to edit anything there, but the issue is regarding the execution of the chrome.tabs.executeScript() which is used for injection of the scripts. I am trying to run a background script using the chrome .tabs.executeScript but it gives the following errors :