content-script

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

只谈情不闲聊 提交于 2019-11-28 20:47:00
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 userscript port. The script works perfectly with Tampermonkey with the setting run at to document-start

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

时间秒杀一切 提交于 2019-11-28 19:56:39
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 call that first sendMessage line from my content script , it throws this exception: Error: Error

Hijacking a variable with a userscript for Chrome

*爱你&永不变心* 提交于 2019-11-28 18:59:26
I'm trying to change the variable in a page using a userscript. I know that in the source code there is a variable var smilies = false; In theory I should be able to change it like that: unsafeWindow.smilies = true; But it doesn't work. When I'm trying to alert or log the variable to the console without hijacking I get that it's undefined. alert(unsafeWindow.smilies); // undefined !!! EDIT: I'm using Chrome if it changes anything... http://code.google.com/chrome/extensions/content_scripts.html says: Content scripts execute in a special environment called an isolated world. They have access to

Adding complex HTML using a Chrome content script

让人想犯罪 __ 提交于 2019-11-28 16:54:44
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 know or can think of a clever way to get a better workflow on this. Brock Adams It's relatively easy to

Chrome extension regarding injected script + localstorage

纵然是瞬间 提交于 2019-11-28 14:29:45
I am puzzling my way through my first 'putting it all together' Chrome extension, I'll describe what I am trying to do and then how I have been going about it with some script excerpts: I have an options.html page and an options.js script that lets the user set a url in a textfield -- this gets stored using localStorage. function load_options() { var repl_adurl = localStorage["repl_adurl"]; default_img.src = repl_adurl; tf_default_ad.value = repl_adurl; } function save_options() { var tf_ad = document.getElementById("tf_default_ad"); localStorage["repl_adurl"] = tf_ad.value; } document

how to make on/off buttons/icons for a chrome extension?

二次信任 提交于 2019-11-28 12:14:16
I want to let the user decide when they want to run a script, so that when the browser opens, the "off" icon is showing and no script runs; but when the user clicks it, it changes to an "on" icon and executes a userscript, until the user clicks off. I have two png icons which are 32x32 each: on.png and off.png . My two questions: How can I set the default icon to my off.png? I tried this in my manifest.json but it didn't set the icon, instead showed a puzzle piece (I presume a default): ... "browser_action": { "default_icon": { "32": "off.png" }, "default_title": "icon" }, "icons": { "32": "on

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

感情迁移 提交于 2019-11-28 12:07:07
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": "Extension", "description": "Description", "version": "1.0", "content_scripts": [{ "run_at": "document

Chrome Extension: How to detect if an extension is installed using Content Scripts

自古美人都是妖i 提交于 2019-11-28 09:23:08
问题 I am asking this question after looking at several related questions on stackoverflow. I started with how to detect if an extension is installed. I opted for the method where I add a div to body using content scripts on some pages. Here is how I did it... manifest.json { "name": "Install Check", "content_scripts": [ { "matches": ["http://host.com/*"], "js" : ["insert_node.js"] } ], "permissions": [ "tabs", "host.com/*" ] } insert_node.js (content script) var insert_node = document

Debugging Content Scripts for Chrome Extension

六眼飞鱼酱① 提交于 2019-11-28 08:52:28
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 page example extension, it is brought in via this code block in background.js: chrome.tabs

Difference between background script and content script in chrome extension

此生再无相见时 提交于 2019-11-28 06:51:10
As the questions says, I just want to know the difference between background script and content script in chrome extension. When I logged the chrome object in both the scripts, I found the different objects. Use case I want to inject my javascript into the page when the icon is clicked So in manifest.json I added a content script but I am unable to listen to icon click event inside content script. chrome.browserAction is not defined in chrome object in content script. Question How can I listen to click event in content script. Can we include both background and content script ? This is my