google-chrome-extension

chrome extension API for refreshing the page

落花浮王杯 提交于 2019-12-29 03:54:10
问题 Is there an API to programmatically refresh the current tab from inside a browser action button? I have background page configured, which attaches a listener via: chrome.browserAction.onClicked.addListener(function(tab) { ... }); So the callback function retrieves a reference to the tab that it was clicked from, but I don't see an API anywhere to refresh/reload that tab. 回答1: I recommend using chrome.tabs.executeScript to inject javascript that calls window.location.reload() into the current

Update object stored in chrome extension's local storage

房东的猫 提交于 2019-12-29 02:01:06
问题 I'm developing a chrome extension and I will store objects sent by server. For example, I will receive: command = {id:"1", type: "A", size: "B", priority: "C"} If I had a database, I would insert it as a line in table commands . Using chrome.storage, I'm storing an array of these object in key commands . But, when I receive a new command by server, I have to get from local storage, update the array and then set again. I'm worried about cases when I receive another command while I'm getting

How to check if a tab has been reloaded in background.js?

一个人想着一个人 提交于 2019-12-29 01:47:16
问题 I am writing a Chrome extension which needs to detect if the tab has been reloaded, that is to say, the user refreshed the page (either by pressing the refresh button, or put a cursor behind the URL and press Enter) with no URL change. If it happens, then I will reinitialize my variables defined in background.js . I am wondering how could I get this " is_reload " boolean value? I tried to make use of windows.performance.navigation.type , but it doesn't have any effect in the background.js .

chrome extension context menus, how to display a menu item only when there is no selection?

可紊 提交于 2019-12-28 22:05:13
问题 What I want to do is: if the user does not select anything, display menu item A; if the user selects something, display menu item B. So far what I can get is: if the user does not select anything, display menu item A; if the user selects something, display both A and B. I want to know: how to make item A disappear when there is selection? Many thanks! Below is my code: var all = chrome.contextMenus.create ({ "title": "A", "contexts":["page"], "onclick": doA }); var selection = chrome

Reading documents CSS in Chrome Extension

依然范特西╮ 提交于 2019-12-28 18:44:10
问题 I am trying to read the pages CSS using a chrome extension. This is what i have in my content script : var allSheets = document.styleSheets; for (var i = 0; i < allSheets.length; ++i) { var sheet = allSheets[i]; var src = sheet.href; var rules = sheet.cssRules || sheet.rules; } For some reason the rules are always empty. I do get all the CSS files used in the 'src' variable. But the rules always come as null.. Its working when I try it as a separate javascript on a HTML page. But fails when I

Re-enabling extension installs

余生颓废 提交于 2019-12-28 13:56:20
问题 I found the new change that you can't install Chrome extensions/userscripts without saving them and dragging them into Chrome quite annoying. As such I have set forth to revert this to the old way it was. I read the documentation here: http://www.chromium.org/administrators/policy-list-3#ExtensionInstallSources that says to add a registry key and so I have done, as shown below. However when attempting to install an extension I still get an error that they can only be installed from the Chrome

Chrome extension: Checking if content script has been injected or not

我的梦境 提交于 2019-12-28 13:34:11
问题 I'm developing a Chrome extension. Instead of using manifest.json to match content script for all URLs, I lazily inject the content script by calling chrome.tabs.executeScript when user do click the extension icon. What I'm trying is to avoid executing the script more than once. So I have following code in my content script: if (!window.ALREADY_INJECTED_FLAG) { window.ALREADY_INJECTED_FLAG = true init() // <- All side effects go here } Question #1 , is this safe enough to naively call chrome

Chrome extension: Checking if content script has been injected or not

与世无争的帅哥 提交于 2019-12-28 13:34:05
问题 I'm developing a Chrome extension. Instead of using manifest.json to match content script for all URLs, I lazily inject the content script by calling chrome.tabs.executeScript when user do click the extension icon. What I'm trying is to avoid executing the script more than once. So I have following code in my content script: if (!window.ALREADY_INJECTED_FLAG) { window.ALREADY_INJECTED_FLAG = true init() // <- All side effects go here } Question #1 , is this safe enough to naively call chrome

How to trigger an event only when the user changes the URL?

ε祈祈猫儿з 提交于 2019-12-28 07:04:31
问题 I am working on a Chrome extension, I want to detect when the user has typed a URL. I know about: chrome.tabs.onUpdated.addListener(eventLisenerObj.onUpdated); But, it gets called whenever the URL is changed (e.g. when the page is auto reloads, or user clicks on a link, etc.) I desire to be able to determine that the URL was changed only by the user typing a URL. 回答1: You can get this information using the webNavigation.onCommitted (MDN) event. The event listener receives a property

Trigger shortcut in a Chrome extension

南楼画角 提交于 2019-12-28 06:50:48
问题 I am building a Chrome extension, and assigned command _execute_browser_action to Alt + J . I want to simulate this in background.js which listens for all commands using chrome.commands.onCommand.addListener(function(command) { /* ... */ }); I want _execute_browser_action to be called through a different command shortcut, say Cmd + Shift + K In my manifest.json I have declared the following: "commands": { "_execute_browser_action": { "suggested_key": { "mac": "Alt+J", "linux": "Ctrl+Shift+J"