Force extension become inactive - google-chrome-extension

With manifest v3 the service workers become inactive after few seconds, but they stay active for a long time if devtools is opened (way beyond 5 minutes).
I need to test how my extension handles its active/inactive cycles. How can I force it to become inactive while devtools is opened?
(can't use devtools persistent logs for action popup, because it's being cleared each time)

Open any visible page of your extension like the popup or the options
Open devtools for that page (right-click the page, then choose "inspect")
Go to Application tab, then Service Worker on the left.
Now you can click Stop and Start to control the background script. You can also debug it and set breakpoints in this devtools.
If your extension doesn't have any page, open any file in a tab e.g. chrome-extension://ID/manifest.json where ID is the id of your extension. A quick method of doing it is to right-click any file of your extension in devtools Sources panel, then choose "Open in new tab".

You can also stop/start/unregister/inspect service-worker in this url chrome://serviceworker-internals/

Related

Is there a way to hide a Chrome browser tab via an extension?

We have a software which uses a browser tab to hold the connection between client and server.
Users accidentally close the tab and have connection issues.
I want to program a Chrome extension which scans all new tabs. When this special tab is identified, I want to move this to a new window and hide this window, so that the user can't close the tab by mistake.
Is this possible with a Chrome extension?
Thanks.

Opening a Chrome extension as a pop-up using a link

I have a chrome extension installed in my browser. When I click the extension's icon in the menu bar the extension opens as a floating pop-up, as expected.
What I am trying to do is to open the extension in Chrome via a link/shortcut/whatever from another program. As a first step I've tried opening the extension from the command line, ex:
chrome "chrome-extension://abcdefghijklmnopqrstuvwxyz/index.html"
This works but the extension opens as a new tab and takes up a full broswer page instead of a just being a pop-up. Is there a way to open the extension as a pop-up on top of any open tabs?
Sadly, it's completely impossible.
There is an API in the works, but it would require at a minimum a user gesture, at a maximum explicit invocation of the extension.
So opening a link would not be enough, nor would a Native Message be.
you cant make the native extension popup to show programatically but you could use a content script that displays the popup (using the new for example) on the tab that you want.

How can I remain on same page window on Chrome browser extension when it closes?

I'm developing a Chrome browser extension that that has different menu links that go to different pages in the extension. I noticed each time the extension closes I have to navigate back to the last page I was on in the extension.
Is there a way to keep the last page I'm on current even if the extension window closes?

Reload chrome extension after taking user input from options page

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()

Making extension always opened once the user clicked in the extension icon, only close when the extension icon is clicked

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.

Resources