I am trying to make a simple chrome extension, which shows some options on right click. There is an options page where the user can enter his preferences(what options to show on right click and what not to). When the user's preferences are saved, they are not reflected in the behavior of the extension until it is reloaded or chrome is restarted. How can I avoid this? I want the changes to come into effect immediately.
You can reload your extension by reloading the background page:
chrome.extension.getBackgroundPage().window.location.reload()
Related
I am developing a Chrome extension with Parcel and when I refresh any page, my Chrome extension's icon will do the reloading animation (it disappears and quickly animated in from the right). This is a problem because it seems to be resetting my background script which contains some variables that need to persist. I'm not sure where to look because there aren't any errors logged.
I have a Chrome Extension (page action). The extension is loaded in developer mode (not from the store).
The extension is used in two sites, both of which URLs are in the manifest.
When I go to one of the sites, the page icon is enabled and when I click it, it runs fine.
When I go to the other site, the extension icon is also enabled but when I click on the extension, instead of running the action, the extension menu appears (as if I had right-clicked the icon instead of clicked it).
When I hover the page action icon, in both sites I get the text "Has access to this site".
Which are possible causes for this behavior?
Something definitely changed with the manifest.json handling of the most recent Chrome update. (In my case, "Version 72.0.3626.96 (Official Build) (64-bit)" on Windows.) My extension stopped working in a way similar to what you describe.
The solution to my problem was to remove the specific url permissions I had specified in the "permissions" section, and replace them with <all_urls>. I tried tightening them back up again, but the only other thing that worked for me was https://*/*.
I tested this on several machines that had the previous version of Chrome and they had the same behavior... successful operation before the Chrome update, no response after. The icon displayed properly and showed "Has access to this site", but my background page refused to run.
Good luck! Hopefully this helps!
I am learning to write chrome extensions. Sometimes ,i do want to learn from the examples given on the chrome developer site. As the instruction says, i need a browser_action or a page_action, then right click ,then inspect popup. I am wondering whether there is other ways to debug the chrome extension.
And the other thing is , i have to write "window.reload(true)" in the debug console to reload the popup page, is there a better or more convenient way to do it?
Of course it's not needed. Your extension either has a popup of some sorts, a background script of some sorts, or a content script of some sorts.
You already know how to debug a popup.
To debug a background page, you can go to chrome://extensions/ with Developer mode enabled. Then you'll see a "background page" link next to extensions that have them - you can click that link to bring up Dev Tools for the extension.
To debug a content script, you should look into the page's own Dev Tools. The console output will be displayed alongside normal console. To type code in the console to execute in the extension's context, you need to change the the context from <top frame> to the extension in the UI:
Depends on what you want to debug.
Chrome extensions also have background page and content-scripts.
Background page console you can find here: open chrome://extensions/ and under extension you'll see "Inspect views".
Content-scripts print messages to the page console.
Popup and other pages you can open in normal tab and inspect in its console. They are accessible by the url: "chrome-extension://YOUR_EXTENSION_ID/path/to/popup.html"
I am new to Chrome Extension. I have a popup.html that collects data and displays when mouse over on the current open page/tab. I also send data to popup.html on click on the current open page/tab.
The problem is when i click on the page data gets passed to the popup.html but popup.html disappears/closes. When i click on the extension again the data persists since i am persisting the data on a background page.
How do i avoid popup.html not to close/disappear on click on current open page/tab.
Thanks in advance
It is not possible.
The popup for Browser Actions / Page Actions is designed to close as soon as it loses focus. It is also not possible to programmatically open it.
You did correctly by making the background script handle the data. If you need persistent UI while you're interacting with a page, then your only option seems to be some HTML UI injected by a content script.
You might be interested in this question.
I understood that pop.html does not persist on the screen, hence took up a different route by getting my extension on to the chrome dev tools. They perform the same actions such as an extension the pain is that your dev tools have to be open always.
For my use case keeping the console open does not make much of a difference. This post helped me a lot set this up.
Thanks for your suggestions
I m not sure u can. There is a reason the page is named as popup. Although you can try notifications(https://developer.chrome.com/extensions/notifications) to provide the same functionality.
I want my extension, once it is opened (clicked on the icon), to only be closed when the user click on my extension icon , like it happens when you have developer mode on and 'Inspect Pop-up', when it's in developer mode you can only close your extension after you click in the icon of it in the chrome.
I would like to make it visible until the user click on the extension icon (not any click outside) to close it but without having to have the developer mode on.
or if this is not possible I would like to at least once my extension is clicked, make my extension active so it can deal with the chrome.webRequest.onBeforeRequest.addListener()
Thanks in advance.
Take a look at background pages. As the documentation says a background page is
a single long-running script to manage some task or state
It should work if your aim is to achieve such a task.
Maybe, Desktop Notifications are some kind of decision.