google-chrome-extension

Chrome extension, javascript: Why is this firing twice?

给你一囗甜甜゛ 提交于 2020-02-11 04:42:25
问题 I have a very very simple bit of code in my (test) Chrome extension: function test() { alert("In test!"); } chrome.tabs.onUpdated.addListener(function(tabid, changeinfo, tab) { var url = tab.url; if (url !== undefined) { test(); } }); My question is, why is test() firing twice? And more importantly, how do I make it fire just once? 回答1: Have a look at what the different states are when the event is dispatched. I presume, that it is getting dispatched once when the state is "loading" or when

Chrome extension, javascript: Why is this firing twice?

好久不见. 提交于 2020-02-11 04:41:11
问题 I have a very very simple bit of code in my (test) Chrome extension: function test() { alert("In test!"); } chrome.tabs.onUpdated.addListener(function(tabid, changeinfo, tab) { var url = tab.url; if (url !== undefined) { test(); } }); My question is, why is test() firing twice? And more importantly, how do I make it fire just once? 回答1: Have a look at what the different states are when the event is dispatched. I presume, that it is getting dispatched once when the state is "loading" or when

Chrome extension, javascript: Why is this firing twice?

て烟熏妆下的殇ゞ 提交于 2020-02-11 04:41:06
问题 I have a very very simple bit of code in my (test) Chrome extension: function test() { alert("In test!"); } chrome.tabs.onUpdated.addListener(function(tabid, changeinfo, tab) { var url = tab.url; if (url !== undefined) { test(); } }); My question is, why is test() firing twice? And more importantly, how do I make it fire just once? 回答1: Have a look at what the different states are when the event is dispatched. I presume, that it is getting dispatched once when the state is "loading" or when

Stop page load and redirect in a content script

橙三吉。 提交于 2020-02-07 06:09:50
问题 I am making a extension in Chrome and need to stop a page load (without loading the page completely) and redirect to a url if matches from ajax query. I am using content_scripts . And tried to use window.location.replace("http://facebook.com"); But the redirect occurs once the page load is completed.. Even tried to use window.stop(); this is also not working to stop page loading. Is there any possible way to stop a page load and redirect it before page load? 回答1: You're trying this with a

Alternative to MutationObserver for synchronous notifications

对着背影说爱祢 提交于 2020-02-06 15:43:05
问题 I need synchronous notifications of DOM changes a la MutationEvents for an extension capability. MutationEvents, however, are deprecated. MutationObserver is limited in usefulness because of the way it aggregates changes and delivers them after the changes have been made. So, simple question. Is synchronous notification of Element style changes possible in current (2019) browser extensions? 回答1: There's no API other than those you've mentioned. The only additional approach is to hook Node

Change Context Menu Icon

假装没事ソ 提交于 2020-02-05 04:45:32
问题 Is it possible to change the context menu icon during runtime? There seems to be no option in the update method. 回答1: I think what you're looking for is the setIcon method of the BrowserAction. Within the ContextMenu you can only specify the items shown in the menu, not configure the icon itself. http://code.google.com/chrome/extensions/browserAction.html#method-setIcon 回答2: It's been possible for some time, include a following line to the root of your manifest.json file: "icons": {"16":

how to access IndexedDB (of current opened domain/tab) from chrome extension

假装没事ソ 提交于 2020-02-05 04:23:26
问题 I currently have indexedDB on google.com domain. i want to be able to read it from google chrome extension. how can i accomplish this? do i need to add any specific permissions? i currently have: "permissions": [ "tabs", "bookmarks", "unlimitedStorage", "*://*/*", "identity", "https://*.google.com/*", "https://ssl.gstatic.com/", "https://www.googleapis.com/", "https://accounts.google.com/" ], with what command i can do this? thank you! Edit: i have readed i can access it from content script

How determine if the popup page is open or not?

时光毁灭记忆、已成空白 提交于 2020-02-03 04:58:48
问题 I'm working on a Chrome extension and I'm looking how to find out (from the background page) if the popup page is open or not. I looked into message passing but I'm not sure if that's gonna help me at this or if there's a simpler way. Thanks! 回答1: You can use the following chrome API call from your background page fetch if the popup view is open: var views = chrome.extension.getViews({ type: "popup" }); //views => [] //popup is closed //views => [DOMWindow] //popup is open If it returns an

Chrome.experimental.sidebar gone?

佐手、 提交于 2020-02-02 11:37:30
问题 Does anybody know anything about chrome.experimental.sidebar namespace? Is it still available? Is it going to be removed? Anything? It's not available in the Google Chrome Extensions documentation anymore. Do you know anything about availability of sidebars in Google Chrome? 回答1: You can see all relevant information in the corresponding Chrome bug. To quote comment 41: The sidebar's on ice for now. We're going to go through an API prioritization exercise near the end of the year to figure out

Do elements created with document.createElement stay in memory?

时光总嘲笑我的痴心妄想 提交于 2020-02-01 18:35:12
问题 Hi, I'm slowly making a chrome extension, and I need to parse some data that contains html entities, and I need to decode it. I saw in an answer here that I could use document.createElement for it, so I did this: htmlDecode: function(input) { if(/[<>]/.test(input)) { // To avoid creating tags like <script> :s return "Invalid Input"; } var e = document.createElement('div'); e.innerHTML = input; return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue; } However I'm worried that