How to to initialize keyboard event with given char/keycode in a Chrome extension?

Incase anyone has the issue I faced with triggering a keyup with a specific keycode. This is one way. First off I tried @RobW‘s answer above with no luck. No Keycode passed, always undefined. So then I looked into @disya2‘s answer, which did work. So here’s some code:- Manifest “permissions”: [ “debugger” ], ContentScript.js chrome.runtime.sendMessage({ … Read more

Chrome extension: Communication between content script and background.html

sendRequest/onRequest is replaced with sendMessage/onMessage in Chrome 20. *Message is not just an alias for *Request, it’s a different API. If you want to support Chrome <20 (many Ubuntu users are still at Chromium 18, because the PPA is not updated), use onRequest and sendRequest. Otherwise, use the *Message methods. Another problem is that your … Read more

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

You are injecting your script after the event you are listening for fires (in this case, DOMContentLoaded). Thus, any code that you have in the listener will not be executed, because the event never fires after you have added your listener. In Chrome extensions and Firefox WebExtensions, when specifying a time for a content script … Read more

How to get a content script to load AFTER a page’s Javascript has executed?

“run_at”: “document_end” is the equivalent to DOMContentLoaded. That is, it fires after the static HTML is loaded, but before slow images and slow finishing javascript. So you cannot set a content script to fire after the page’s JS, just by setting the manifest alone. You must code for this in the content script itself. For … Read more

Access variables and functions defined in page context using a content script

Underlying cause: Content scripts are executed in an “isolated world” environment. Solution: Inject the code into the page using DOM – that code will be able to access functions/variables of the page context (“main world”) or expose functions/variables to the page context (in your case it’s the state() method). Note in case communication with the … Read more

How to inject CSS using content script file in Chrome extension?

You could add to the manifest’s permissions field; See web_accessible_resources. So you would add this to the manifest: , “web_accessible_resources”: [ “fix.css” ] See also “Programmatic injection”. and insertCSS(). For most applications, forget all that createElement code and just add the CSS file to the manifest: “content_scripts”: [ { “matches”: [“http://www.google.com/*”], “css”: [“fix.css”], “js”: [“script.js”] … Read more

Overriding !important with css or jquery

Here you go: $( ‘.someclass’ ).each(function () { this.style.setProperty( ‘border’, ‘none’, ‘important’ ); }); Live demo: http://jsfiddle.net/Gtr54/ The .setProperty method of an element’s style object enables you to pass a third argument which represents the priority. So, you’re overriding an !important value with your own !important value. As far as I know, it is not … Read more

sendMessage from extension background or popup to content script doesn’t work

In your background page you should call chrome.tabs.query({active: true, currentWindow: true}, function(tabs){ chrome.tabs.sendMessage(tabs[0].id, {action: “open_dialog_box”}, function(response) {}); }); instead of using chrome.extension.sendMessage as you currently do. The chrome.tabs variant sends messages to content scripts, whereas the chrome.extension function sends messages to all other extension components.

Content script matching top-level domains like all google.*

Listing all Google domains is not that difficult, because Google has published a list of all public Google domains at http://www.google.com/supported_domains. Prefix every item in this list with “*://* and add the “, suffix to every item. Then copy-paste the result to your manifest file. An alternative option is to use the “include_globs” field (this … Read more