content-script

chrome.runtime.sendMessage throws exception from content script after reloading Chrome Extension

喜欢而已 提交于 2019-11-27 12:51:35
问题 I send messages from the injected content scripts back to my background script in my Chrome Extension as such: chrome.runtime.sendMessage({action: "myResult"}); This works fine, until I reload my extension (by going to Settings -> Extensions -> "Reload (Ctrl+R)" for my extension.) In turn when my background script starts up it repeatedly calls chrome.tabs.executeScript for all open tabs to programmatically re-inject my content script (as I showed in this question.) But after I do that, if I

Chrome extension content script re-injection after upgrade or install

江枫思渺然 提交于 2019-11-27 10:29:42
After the Chrome extension I'm working on is installed, or upgraded, the content scripts (specified in the manifest) are not re-injected so a page refresh is required to make the extension work. Is there a way to force the scripts to be injected again? I believe I could inject them again programmatically by removing them from the manifest and then handling which pages to inject in the background page, but this is not a good solution. I don't want to automatically refresh the user's tabs because that could lose some of their data. Safari automatically refreshes all pages when you install or

Adding complex HTML using a Chrome content script

百般思念 提交于 2019-11-27 09:48:11
问题 I am working with Chrome extension's content script to create a complex display that is added on web pages. I have first tested it directly integrated on a website, but now I need to put it in an extension. The thing is that the content script API for Chrome only allows to inject javascript. That means that, to inject complex HTML layouts I would need to write it entirely with JS objects, which is long to write, hard to maintain and absolutely not designer-friendly. I'm wondering if anyone

Overriding !important with css or jquery

别来无恙 提交于 2019-11-27 03:16:47
(This is using content scripts in a chrome extension) I need to overwrite some css properties that the webpage has labeled as !important . Is this possible? For instance, if I want to get rid of the border that is labeled important: $(".someclass").css('border','none'); //does not work 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

Debugging Content Scripts for Chrome Extension

試著忘記壹切 提交于 2019-11-27 02:07:01
问题 General Questions Hello! I'm delving into the world of Chrome Extensions and am having some problems getting the overall workflow down. It seems that Google has recently switched to heavily advocating Event Pages instead of keeping everything in background.js and background.html. I take part of this to mean that we should pass off most of your extension logic to a content script. In Google's Event Page primer, they have the content script listed in the manifest.json file. But in their event

Chrome extension: Run on all google domains and a specific page

拈花ヽ惹草 提交于 2019-11-27 02:02:54
I want my content script to match all google domains, and a specific page. I know this is not possible. Manifest.json "content_scripts": [{ "matches": [ ,"*://www.google.*" ,"*://www.youtube.com/*" ,"*://readthedocs.org/*"] , .... Is there another way to do this? Just wanted to make sure before I list all domains Google has :) 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

Call background function of Chrome extension from a site

自闭症网瘾萝莉.ら 提交于 2019-11-27 01:11:30
问题 I am looking for a function inside a webpage te activate a chrome extension. Imagine that http://www.example.com/test.html contains: <script> hello(); </script> And my background page contains the definition of the hello function: function hello() { alert("test"); } How can I make sure that the Chrome extension's background page's hello is called when test.html calls hello(); ? 回答1: Before a web page is able to call a background page's function, the following problems need to be solved: Be

Access window variable from Content Script [duplicate]

本小妞迷上赌 提交于 2019-11-27 00:51:52
This question already has an answer here: Chrome extension - retrieving global variable from webpage 5 answers Hijacking a variable with a userscript for Chrome 1 answer I have a Chrome Extension that is trying to find on every browsed URL (and every iframe of every browser URL) if a variable window.my_variable_name exists. So I wrote this little piece of content script : function detectVariable(){ if(window.my_variable_name || typeof my_variable_name !== "undefined") return true; return false; } After trying for too long, it seems Content Scripts runs in some sandbox. Is there a way to access

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

六月ゝ 毕业季﹏ 提交于 2019-11-27 00:28:21
问题 My extension is supposed to load a content script, searchTopic.js, only after the page it's injected into has already fully loaded (yes, I have set "run_at" to "document_end" in the extension manifest), but in fact it's loading before all the DOM objects have been created (the crucial ones are created via some Javascript in the page). So, the question is, how can I wait until the page's Javascript has executed? Here's my manifest: "content_scripts": [ { "run_at": "document_end", "matches": [

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

醉酒当歌 提交于 2019-11-26 22:39:55
问题 I'm trying to inject my CSS from JavaScript which is injected as content script: "content_scripts": [ { "matches": ["http://www.google.com/*"], "js": ["script.js"] } ], I found similar question about injecting CSS, but I encountered a problem while using code from accepted answer. Here's my script.js contents: var link = document.createElement("link"); link.href = chrome.extension.getURL("style.css"); link.type = "text/css"; link.rel = "stylesheet"; document.getElementsByTagName("head")[0]