How to prevent browser_action from reloading its popup window every time? - javascript

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!

Related

Display a web page in a container, scroll, switch to next

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.

Chrome extension hidden / non-displayed tab

Part of my extension involves accessing a webpage and then programatically performing certain functions for the user. The app would obviously be much cleaner if the user did not have to see all this happening in a browser window.
In some situations this could be achieved by, displaying other content (useful to the user) in a browser window, loading the screen with the programmatic elements in an iframe and manipulating them through an action script that triggers on the page load of the page loaded in the iframe.
However, for my purposes this is obstructed partially by the cross-domain limitations and totally by the fact that site in question does not allow iframes.
(One solution was to reverse this process--i.e. direct the browser to the correct page and throw up the useful content in front of it, thereby hiding the noise while loading the page in the browser. This works but it is horrible for obvious reasons)
Is there any clean way to either:
Open a chrome window but keep it hidden?
or
Load a page (i.e. have a DOM built etc) without doing so in a window/tab?
Have you tried using
chrome.windows.create({url:yourUrl, focused:false, state:"minimized"}, function(hiddenWindow){
//do whatever with hidden window
});
or having an <iframe> in the background.html of your extension?

How can a Google Chrome extension exit its own background process?

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.

Background Page in popup- chrome extension

I am embedding a dynamic webpage in a popup. Currently its working and every time popup is loaded the webpage is loaded again, thus me losing the work i did on the webpage in popup. Though its fine, but i want that webpage remain loaded in background and i just show it in popup on click. to do this i copied complete code from my pop up page(script+html) to background.html. Now how should i access the page completely in popup and show directly(i want to show html also-from background page)
Thanks
Popups live in the same process (the extension process) as the background page, and one page can get the DOM Window of the other. A popup gets the background page by calling chrome.extension.getBackgroundPage(). So every time you open the popup, just read and write to some variable on the background page, for example chrome.extension.getBackgroundPage().enteredData = "value";.
Alternately, you can use HTML5 localStorage to store variables even after the browser is shut down; e.g. localStorage['enteredData'] = "value".

Hyperlinks to download files without stopping the current page load

I've got an ASP.NET page that takes a long time to download and returns partial results as it's loading (as per my previous question). On the page I have some links to download files, ie. the response headers contain "Content-Disposition: attachment", so that the browser doesn't navigate away from the page. However, if the user clicks one of these links while the page is still loading it stops loading - normal behaviour, but not what I want in this case. I can get around that by adding target=_"blank" to the links, but this momentarily opens a new window and the closes it again (once the browser realises it's an "attachment"). Is there any way to avoid having those links stop the current page load without this new window trick? JavaScript is OK.
You could put a hidden iframe on the page and target that. (or use javascript to generate one dynamically).
Not sure it if will help, but try to add an iframe to the page and have your links do document.getElementById('your_iframe').location = 'your_url'
You could try a meta refresh
<meta http-equiv="refresh" content="2;url=http://path.to/file.download">

Categories