content-script

Call background function of Chrome extension from a site

偶尔善良 提交于 2019-11-28 06:04:52
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(); ? Rob W Before a web page is able to call a background page's function, the following problems need to be solved: Be able to use hello(); from a web page. This is done by injecting a script defining hello using Content

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

夙愿已清 提交于 2019-11-28 04:32:32
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": ["https://groups.google.com/forum/*"], "js": ["searchTopic.js"] } ], "run_at": "document_end" is the

Clipboard Copy / Paste on Content script (Chrome Extension)

别说谁变了你拦得住时间么 提交于 2019-11-27 20:59:57
问题 I am using a Content script to manipulate data in the DOM. I have been using document.execCommand('copy'); successfully on a popup page. I am now searching for a way to make it work on a Content script. I have checked the limitations for content scripts here, but I do not understand if Clipboard control is limited or not. I have also checked answers here - in stackoverflow, but it seems that most are uncertain and some are from a few years ago so there might have been changes. Even if it is

Injecting multiple scripts through executeScript in Google Chrome

孤街醉人 提交于 2019-11-27 18:47:52
I need to programmatically inject multiple script files (followed by a code snippet) into the current page from my Google Chrome extension. The chrome.tabs.executeScript method allows for a single InjectDetails object (representing a script file or code snippet), as well as a callback function to be executed after the script. Current answers propose nesting executeScript calls: chrome.browserAction.onClicked.addListener(function(tab) { chrome.tabs.executeScript(null, { file: "jquery.js" }, function() { chrome.tabs.executeScript(null, { file: "master.js" }, function() { chrome.tabs

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

随声附和 提交于 2019-11-27 18:21:51
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].appendChild(link); After I load some page this message appears in console: Denying load of chrome

Chrome extension: sendMessage from background to content script doesn't work

戏子无情 提交于 2019-11-27 17:07:49
I know that question has been repeatedly asked in different ways, but I tried to go through all the answers (hopefully I didn't miss anyone) and none of them worked for me. Here is my extension's code: manifest: { "name": "test", "version": "1.1", "background": { "scripts": ["contextMenus.js"] }, "permissions": ["tabs", "<all_urls>", "contextMenus"], "content_scripts" : [ { "matches" : [ "http://*/*" ], "js": ["jquery-1.8.3.js", "jquery-ui.js"], "css": [ "jquery-ui.css" ], "js": ["openDialog.js"] } ], "manifest_version": 2 } contextMenus.js function onClickHandler(info, tab) { if (info

How to trigger a Chrome extension, content-script for a given hash in the URL?

不羁的心 提交于 2019-11-27 16:06:54
My matches scheme: "content_scripts" : [ { "matches" : [ "https://stackoverflow.com/questions#epic*" ], "js" : ["silly.js"] } ], So if the user went to a webpage (like https://stackoverflow.com/questions ) then added #epic it would go to https://stackoverflow.com/questions#epic but would have #epic on the end of the URL, which would activate the content script silly.js . That's what's supposed to happen, but that doesn't work. See Content scripts, Match Patterns . Match patterns do not operate on the query nor the fragment portions of a URL. To restrict a content script to a given hash, use

Chrome extension: Communication between content script and background.html

ぃ、小莉子 提交于 2019-11-27 15:28:29
I am new to Chrome extensions. I am trying to communicate between the content script and the background.html page. The background.html sends a request, " hello ", to the content script and the content script should respond back with " hello background " alert. But it's just not happening. My background.html code is: function testRequest() { chrome.tabs.getSelected(null, function(tab) { chrome.tabs.sendRequest(tab.id, {greeting: "hello"}); }); } content.js code: chrome.extension.onMessage.addListener( function(request, sender, sendResponse) { if (request.greeting == "hello") alert("hello

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

风格不统一 提交于 2019-11-27 15:07:57
I'm developing a Google Chrome extension which simulates keyboard events on a web-page. I found that event.initKeyboardEvent() does not work properly because of this webkit bug and I also found some workarounds, e.g. SO Question However, defining properties on event object is not working because extension's content script has its own "parallel world" so properties defined in content script are not visible to web-page script. My only and last hope that DOM 4 Event Constructors work in Google Chrome and it would be possible to properly initialize keyboard event through constructor var event =

Chrome extension set to `run_at` `document_start` is running too fast?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 13:11:49
问题 EDIT: Something was wrong with my Chrome browser and creating a conflict with my script, a full reinstall eliminated whatever the problem source was. If I happen to find out what was causing it I will include it in here. EDIT2: Just to let anyone reading this in 2017 know that I haven't forgotten this and I have never had this problem since my previous edit. EDIT3: It is 2019 and so far I've never had this problem again. I have been learning how to create a simple Chrome extension which is a