Processing heavy operation in background in Firefox extensions - javascript

I am working on a firefox extension that gets the html content from the current tab in the browser. Majority of the processing takes place in popup.js file which is embedded in the popup UI that is displayed on clicking the toolbar icon for the extension. Due to this, the performance of the extension suffers and occasionally I see a spinning wheel while capturing. Is there a way I could move this processing to the background? I am loading a script using the loadFrameScript api when the capture button is clicked.
Is there any such thing as background page in Firefox extensions like in chrome and Safari? If no, please suggest a way to optimize this.

Use a Web Worker, if there is some reason why you can't then can you explain that?

Related

Upload image in chrome extension and extension popup closes

I need to upload image with chrome extension, when file browser is clicked the extension popup closes. How can I handle both the file browser and popup to remain open.
It's a tricky question to answer.
The basic idea is that whenever the popup window loses focus, it is supposed to immediately close, which entails the destruction of the popup's JavaScript context (and your logic breaks as a result). This is not something you can influence.
Modal dialogs such as the file input ought to be an exception, but that doesn't work consistently across all platforms Chrome runs on. Evidence: question, bug.
Whenever you want something to survive popup closing, you normally put it in the background page. This lead to this workaround that places the File input in the background page and triggers its selection from the popup. But there's (unconfirmed) evidence that this does not work anymore. The question above has another, supposedly working answer by injecting the input tag into the current page, but that's subject to failing on "unscriptable" pages such as Chrome Web Store or internal chrome:// pages.
The safest way would be to open a separate tab or popup window to handle the process. This is obviously awkward UX though.
Not sure if you'd actually want to do this, but if you have a small app and it's not a main feat (or you've got high hopes of chrome dev's solving this issue) - as a temp solution you can ask your users to open dev tools while uploading files, popup won't close.
Though you're better off putting your logic into a separate file (eg 'background.html') and opening it from popup as a tab like this:
chrome.tabs.create({url: chrome.extension.getURL('background.html')});

Should JavaScript/jQuery objects disappear when download hyperlink is clicked

We use Atalasoft's web image viewing SDK to display TIF images in a web page. We recently upgraded to their client-side, JavaScript/jQuery based component and discovered some odd behavior. After initializing the control, if a link is clicked to a resource that should be downloaded, the control(s) clear themselves out. The issue exists in Chrome and IE 11 that I have tested.
Since it is a paid SDK, the easiest way to test this is to go to their demo at:
http://www.atalasoft.com/demos/dotimagewebdemo/
Once the page finishes loading, open a developer console and paste in the following (simply adds a download link to a file on their site):
$("body").append($("<div style='position:absolute;right:5px;top:5px;'><a href='/Gallery/WebViewingDemo.zip'>DOWNLOAD</a></div>"))
Clicking the download link will wipe out their controls on the page.
Adding download to the anchor tag resolves the issue in Chrome, but not IE.
Adding target='_blank' resolves the issue in both, but creates an ugly blank window first (that in my experience does not always close).
I am setting headers server-side to tell the browser to download the file rather than displaying it.
I guess my questions are two-fold:
Is it normal for JavaScript/jQuery based objects to disappear/destroy/whatever when a link is clicked to download a file or is this a problem with their implementation?
and
What is the best solution for this (preferably without the blank page showing up)? We need to support mainly Chrome, FF, and IE (most popular desktop versions).
Thanks in advance!

Use window.open to a tab in the background (not switch focus)

I'm using the following code to open a new tab on click of a PDF download.
The problem is the new tab becomes the main tab often before the PDF loads.
How can I make the view stay on the current window (PDF) and open the new tab but not switch to it?
Note: In Chrome and Opera they understand the HTML5 download tag so the PDF simply downloads and the current window redirects - All good! So this is only a problem on IE & Firefox.
<h2 style="text-align: center;"><a href="http://cdn2.hubspot.net/hub/155045/file-847580737-pdf/Stepping_into_a_new_age_of_marketing_with_CRM_FINAL_APPROVED.pdf" onclick="casestudiesopen()" download><strong>Click here to download your eBook</strong></a></h2>
<script>
function casestudiesopen() {
window.open("http://www.workbooks.com/case-studies");
}
</script>
Well, I'll advise you to read this Stackoverflow answer, which is, in a way, quite similar to yours (the purpose anyway) :
Javascript disable switches current tab functionality in browser
JS/JQuery is indeed very powerful but also have its limits. Imagine a web page always requesting and keeping focus once you've opened it. I think you would be really annoyed, among other things.
That's why browsers prevent those kind of actions. Common browsers at least. Meaning, there's no way to prevent a browser like Firefox, Chrome, IE & Co. to focus a table since it depend of user's parameters.
You'll have to find a way to workaround your problem. I can propose this answer since it seems to have worked for the other guy.

google chrome keeps on loading my site

I'm making my personal website using a lot of jquery and the basic HTML5/CSS3. I just put some $(document).ready(), maybe that's where the issue comes from..
As I'm trying to see how browsers deal with it, I figured out that google chrome keeps on loading (something but what?) the page. I mean the wheel is spinning in the tab panel and at the bottom of the page, I have a bar saying "Waiting for localhost...". I don't have this issue with Internet Explorer for instance.
How can I find where the problem comes from? Is it just a bad interpretation of chrome? The bar at the bottom is actually quite annoying...
I've been through this:
Try to load the page in anonymous mode (⇧+⌘+N) - if there is no spinning
I would bet on an network activity caused by an extension - check the list (chrome://extensions/) and try to disable a few

Prevent page from reading changes made by extension

I'm writing a chrome extensions which will make some changes to a page using an injected content script. I don't want the page to reverse these changes or read them. Is there any way I can do that?
If it's not possible with content scripts, is there any other way to do it in a chrome extensions?
You can't lock your DOM changes from further modification by the page, there's nothing you can do to prevent the page from reverting any changes your extension makes. The best you can hope to do is capture any events and attempt to block or reverse, but anything like that is likely to be very code intensive.

Categories

Resources