My goal is very simple: when the user installs the extension, open the options page.
The only way I know how to do that is to create a background page, and on that page check for localStorage.setup. If it is not present, set it to true and open the options page. This approach works, but, besides being convoluted, it's inefficient. Not only will the background page load every time the user opens the browser, but it will constantly be running in the background.
Is there any way to tell chrome the background page is finished, and should be exited? Or is there any way for an extension's background page to prevent itself from being loaded in the future? Or, is there a better way to solve my problem?
With transient background pages, the background page will exit automatically once all code that it's running finishes. This feature will be in a future Chrome release, but since it's still under active development, there isn't documentation for it yet.
Related
I have a list of urls I need to show on a screen for a presentation. After the page have loaded, I want to scroll to the end of the page, and when it's reached load the next one.
The problem is, most of those pages have 'X-Frame-Options' to 'sameorigin', so I can't use iframes. What other options do I have ?
I thought about, maybe, a chrome extension will complete rights over navigation that would handle the whole process...
Thanks ahead.
So, the solution was indeed to build a Chrome extension. Only the software containing the page gives you that much control over it when you don't have access to its code - namely, the browser.
I built a very simple extension using chrome.tabs in the background to open a new tab or update it, injecting a script in the page whenever it's loaded, and using messaging to inform the background when scrolling is finished and it's time to load a new page in the list.
I'm developing a webextension and I'm stuck with following problem.
I have browser_action that displays popup window with some content. The problem is, it takes 3-4 seconds to load, and user has to wait every time he opens this browser action.
I want somehow force browser_action to load DOM of popup window just once, so when I open this action again it shows me already rendered window.
I can't preload any assets through background script, because the asset is <iframe> of remote website and you can't easily store rendered DOM in localStorage just to display it later on user request.
I thought about putting <iframe> inside background script and displaying it somehow in browser_action popup window, but I failed to find out how to do that.
Background page is loaded once and stays forever while extension is enabled, so maybe I could display it contents inside browser_action popup window somehow?
Unfortunately, I don't think that's not possible. Your best bet would be to show some useful UI while the iframe loads.
It's certainly not possible to make the popup page itself be persistent.
And I'm 98% positive you can't swap in a loaded tab/frame into the page of the popup. Chrome does it internally sometimes (preload then swap, see tabs.onReplaced), but you have little control over this mechanism.
It seems you can trigger it with preload links:
<link rel="preload" href="https://example.com/"
as="document" crossorigin="anonymous">
However, it serves little purpose to embed that into the popup page (it will be fetched when the popup loads, which is milliseconds of difference) and I'm reasonably sure that preloading it from, say, the background page won't carry over to the popup, despite them normally sharing the browser process. You can experiment though!
When I disable the extension that I am developing, the content that I injected remains on the page (and things get messy since the JavaScript is no longer hiding the content). Is there a way that I can recognize the event and reload the page when it is disabled?
Yes its possible to detect the situation, thou i think its fine if the user needs to refresh manually uppon uninstall/disable.
One way is to regularly message your extension from the injected script to check if its still alive. I do this for an extension of mine to detect when chrome updated it, which has similar consequences as the old version of the background script goes away without notice and the content script is left orphan.
Unfortunately, I don't think there is - somewhat by design. Extensions are intended to run on top of web pages, and the web page shouldn't typically modify its behavior for extensions. This abstraction, though, results in web pages being unaware of an extension's running state.
If you are the one disabling the extension, you could make a "clean up" method which refreshes all pages on which the extension is running, but you'd have to manually trigger that prior to disabling it.
I am new on add-on development using the SDK.
I want to ask you guys if it is possible to start my extension automatically after I open my browser? At the moment I starts after I press my widget icon in the toolbar (the panel shows a table with some data I get from the DOM).
Another thing I want to ask you: is it possible to show a loading screen (like a ajax gif) inside my panel (my extension needs a few seconds after switching a tab, to get the DOM data) every time I press the toolbar button.
First of all: One question per post, please.
Extensions are always started with the browser. When it comes to SDK add-ons, your main.js will be called. It's your job to perform any additional initialization form there.
Panels contain regular HTML pages and therefore can use images.
It's impossible to tell you more, without you providing more details and the code you got so far!
I am working on a project that runs in Chrome in full-screen mode and displays data that can be edited and interacted with. It makes AJAX calls(using jQuery) frequently that cause a loading notification in the lower left-hand corner on the bottom of the screen to pop up.
These notifications are distracting when you are viewing the display and I would like to remove/prevent Chrome from displaying these loading notifications at all. Is it possible to prevent these notification by any means, or perhaps even mask the javascript that causes these notifications?
Do the requests in a web worker thread.
If this is just a simple web page, there is no way to do so. As Dave stated, the notification is part of Google Chrome.
If it is absolutely necessary for this to not appear, you can create a Google Chrome Extension that users can install. Then, you can make the AJAX requests from the extension background page, and the status bar will not popup. However, this is not very user friendly and quite unpractical.
I wouldn't have thought so - those notifications are part of Chrome itself, not the web page. It might be possible for the user to disable the status bar, but that would be part of the browser settings rather than the page.