chrome extension occurs multiple times in Task Manager - google-chrome-extension

Sometimes my extension stops working (clicking the browser action doesn't do anything, it stops doing its background activites). I'm debugging that problem.
When it stops working, if I click 'background.html' to open the background page, I get a blank white window instead of the background page (none of the panels open). Reloading the extension from 'chrome://extensions' doesn't allow me to get the background page either. I have to completely quit the browser and restart. If I keep the background page open and then the extension stops working, the JS console doesn't work. I can't use the 'Sources' tab to find out what stack frames are executing etc.
I also noticed that the extension occurs multiple times (multiple adjacent rows) in Google Chrome's own task manager. But I'm unable to select them individually. Clicking one row selects them all.
Anybody seen this before?
Could this occur if my extension code gets into an endless loop? I don't see high CPU usage either at the OS level or in Google Chrome's task manager. Same behavior under both Mac and Linux.
FWIW the extension is relatively complex: it uses web workers, 10s of uploads and downloads in the background page.

Related

Chrome Dev Tools Extension - Manifest 3 background script options

I have written a debugger for K2 SmartForm web pages, as a Chrome custom panel extension, think of the Vue.js or React Devtools for a similar concept but it is Manifest 2 and I need to convert to Manifest 3.
The debugger injects into the user's SmartForm and sends every event generated on the form to the extension. When a user interacts with the form it might rapidly generate three events or 100 events and as it is user generated, the events may be rather sporadic with long pauses between events.
I use a background script to move messages from page to panel but the background script in its current form is going away. The script needs to be long running but I have read there are some issues with service workers spinning down. I think I can open a new tab to run the background script, not perfect, but it’s an option, as the audience is developers, and they’ll understand the rationale. I also wonder if it is easier than rewriting as a service worker before the end of the year (this is a side project).
What is recommended in the current versions of Chrome for keeping a message channel like this open? If it is the background script in a new tab, is there a sample project I can download?

Creating a Chrome extension which closes blocked websites

I recently blocked quite a lot of ads across my entire network using AdGuard. Unfortunately, AdGuard does not prevent pop-up windows from opening. Although the advertising page is not called up, I get a popup which tells me that the requested page cannot be reached.
That's why I wanted to write a chrome extension that closes these popups automatically. Unfortunately, I fail to save the value of a checkbox in chrome.storage that is supposed to activate / deactivate the extension.
could someone help me here?
:EDIT
Okay i managed to store my value but now i'm running into the problem that i need to run a script when a page can't be loaded and i got no idea how i can do that. :S
Any Ideas? Is that even possible?

How To Hide Chrome Web Driver Icon (Python-Selenium)

UPDATED WITH REASONING
Goal: Run chrome web driver in background without showing an app icon in the dock or application bar. FYI: I can already run chrome headless, but I have not been able to hide or not show the chrome icon in my app bar.
Reason: I am building an application that accesses various websites in parallel and I would not like the chrome app icons to display for the synchronous tasks that are taking place. I want to run these tasks in the background.
Current Code with chrome options that will display headless chrome
chrome_options = Options()
chrome_options.add_argument('headless')
chrome_options.add_argument('window-size=1200x600')
driver = webdriver.Chrome(executable_path=executable_text, chrome_options=chrome_options)
Research
list of chrome options: https://peter.sh/experiments/chromium-command-line-switches/
one of many posts explaining how to do headless chrome: Selenium - chrome Driver fail to start in background (without a start-up window)
How can I hide the chromedriver app icons from displaying? Is there a chrome option I can set in addition to setting the 'headless' chrome option? Is this more of an OS setting that needs to be made to run chromedriver in the background? I am successfully able to run multiple chromedrivers in headless mode but it would be nice to NOT show the chrome icons in the dock or application tray similar to how phantomjs does not launch an app icon.
^In the image above those are the chromedrivers that run in headless mode displaying in my dock and ideally for my program I would not even want to display those icons since it is all background processing anyways.
Update (this worked for me to hide the chromedriver icons at least on my Mac):
I was not able to find a Chrome Option to accomplish hiding the chromedriver icons that appear in the dock. However, I was able to edit the Info.plist file for Chrome as part of my program to do the trick (of hiding chromedriver icons) using the LSBackgroundOnly key.
In the Info.plist for Chrome, programmatically, I entered:
<key>LSBackgroundOnly</key>
<string>1</string>
On my Mac using python3 code I used os.system to execute a terminal command using defaults to enter the LSBackgroundOnly key when the program is executing and then at the end of program execution I delete the LSBackgroundOnly key from the Info.plist.
like this:
1)
defaults write /Applications/Google\ Chrome.app/Contents/Info.plist LSBackgroundOnly -string '1'
2)
defaults delete /Applications/Google\ Chrome.app/Contents/Info.plist LSBackgroundOnly
AS INFO: This is tricky because your normal chrome app may start up in background mode if you don't add/delete LSBackgroundOnly properly during program execution. In my experience, worst case scenario you may have to manually remove LSBackgroundOnly from the Info.plist file then restart your computer to get Chrome out of background mode.
I remove the LSBackgroundOnly key from the Info.plist file in my program after program execution because the key only needs to be in the file when the chromedrivers are launched. After that I want to be able to use regular Chrome app without issues of it opening in background mode. But, if you understand your program execution and handle your exceptions, this will definitely work to hide the icons correctly and there will be nothing different in using your regular Chrome app.
Happy hacking.
This is not possible using Selenium. I don't really understand why you want to do this. Is there a real purpose, or it's just you don't want it to show? Even if the Chrome app shows on the dock, in headless mode, it works pretty good.
However, if you want your icon to not appear in the dock when opened, then you need to disable it by modifying the Info.plist file for that application.
In your Info.plist for Chrome, add this
<key>LSUIElement</key>
<true/>
This will prevent your app icon from appearing in dock, when working. I found this out a long time ago and this is the post where I saw it.
PS - I have not tested it for Chrome app. Please test at your own peril.

Chrome extension pauses before loading

Question
How do I reduce the time between clicking an extension icon and the content being displayed?
Support
I'm making a very simple extension. It loads quickly once it's started, but there is a bit of a delay between clicking and the popup loading. I've added a gif of this here. (The gif gets a bit hectic to look at, so I've put it under a link so that it doesn't burn your eyes!) It doesn't really do it justice as it loads faster on my machine than other people's for some reason.
This question (Slight loading delay with chrome extension popup) seems to address the same question, but it doesn't have an answer. I think that this question (load chrome extension popup faster) addresses this issue too, but its answer seems to be addressing a different problem.
My repo is here: https://github.com/bvn-architecture/shackleton
If I profile the load time of the extension it starts measuring from when the popup appears:
This implies that there is something on the screen about 5ms after loading. It doesn't include the pause.
I think the delay you are facing is due to the time necessary to launch a new task process in Chrome.
Open Chrome menu > More tools > Tasks manager, you will not see any reference to your extension.
Now click on your extension browser-action icon, you will see that, after some various delay, a new entry called "Extension : BVN toolbar" will appear in the tasks manager. Once the task appears, your popup opens.
Some tests
If you test the My Bookmarks sample extension from the Chrome extension samples, you will see the exact same behavior.
Now if you have a look at some other extensions like Adblock Plus for example, which uses a browser-action icon/popup like you, you will see that its popup opens much faster than yours.
If you check the tasks manager again you will see a task named "Extension : Adblock Plus" even when the popup is not opened.
Explanations
This is because many extensions (like the Adblock one) are using persistent background pages which are single long-running scripts existing for the lifetime of your extension (until you disable it, close your browser etc.)
As mentioned in the documentation, the use of persistent background pages is discouraged in favor of event pages (non persistent ones). But in your case, using an event page will not solve your problem because when the event page is not actively doing something, it is unloaded to release resources.
Solutions
The easy way
Defining a persistent background page in your manifest.json file will solve your problem but will result in a not really necessary memory usage to keep your extension task "alive" (and your extension don't need it to work):
"background": {
"page": "popup.html"
},
The other way
Submit the question / problem to Google. Maybe they can perform some optimizations for such case or they will provide you a better solution. And you can explain that this encourages the use of persistent background page instead of event ones :-)

Chrome extension performance

I have developed a chrome extension. The extension itself works fine and fast.
But when I start the browser and click on the toolbar icon of my extension it takes about 2 seconds for the popup to appear and to show its content (this happens anytime the browser is restarted).
Any idea what causes this and how to fix that?
Tip 1:
Use your popup page for rendering exclusively. It should be as light as possible. All the heavy loading/processing (localStorage, XMLHttpRequests, blocking javascript) must be done in the background page.
The background page is loaded when Google Chrome starts. Basically, it allows you to execute code and keep a page always running (although the popup is not present). For instance, streaming audio in a html5 tag with no popup.
Note: If you are not using a background page yet, you should be taking a look to message passing first.
Tip 2: Warning: This could fail
I haven't tested this yet, but maybe using the HTML5 manifest.cache can help you preventing loading again resources stored locally. But beware, this is HTML5 and is prone to changes and unstability across versions. (also, I am not completely sure that the cached resources will be loaded in memory before the popup is opened)
Hope it helps!

Resources