Run Firefox extension on window.open() - javascript

Currently my Firefox add-on uses
require("sdk/tabs").on("ready", runScript);
to attach a script to the document (tab.attach()). But my target website opens a link as a new dialog window (minimal window with no tabs) and my add-on doesn't seem to run on it. How do I make it run on minimal window too?

Usually, you either attach a script to a page when the user presses a button (using tab.attach), which means that the page has already loaded and you don't need to wait for a ready event. Or you attach your script to specific pages based on the URL, in which case you should be using a pagemod which waits for the page to be ready by default.

Related

Detect if browser is already loading another page

I am building some JS to install on people's websites. I am trying to detect if browser going away from page my script installed on. It would be easy to listen beforeunload event, but what if my script was loaded after user click on some link?
The events order is:
browser loads page A with my script installed
my script started to load
user clicks on link to page B
browser started to load page B
my script is loaded to page A ← How can I detect browser location is changing right now?
You can't detect this in this specific situation. The act of navigating from page A will stop your script from loading, even before page B has loaded.
The relevant parts of the spec are 7.8.1 Navigating across documents which details what happens when the browser is asked to navigate (the link to page B being clicked in your example). Step 11 says:
Abort the active document of browsingContext.
The abort steps make it clear that any still-in-progress fetching or parsing of the active document are simply discarded.

Chrome Extension: How to run Javascript on page load (without popup open)

I have a Chrome extension that does word substitutions on pages. Currently I have a popup that opens when I click on a browser action which lets the user control whether or not to perform the substitutions. I also have a background script running that sends a message to content scripts when a page refresh happens using a chrome.tabs.onUpdated event handler.
My problem is that when I refresh the page no substitutions are made unless the popup is open (which is only possible when I have the inspect elements panel open on the popup, because otherwise the popup closes when I refresh).
Has anybody had experience with this behavior before? What additional instrumentation should I add to diagnose the problem? Is there a different extension architecture/code arrangement I should be using?
Thanks in advance!
If you use localStorage on a given page you can probably store whether or not to substitute words. I think refreshing a page is similar to opening a new tab, so your script gets reinjected/reloaded rather than staying open and receiving an onupdate message.

In a Safari extension, how do I validate that the open page is a file of a certain format?

I am new to HTML/JS and I'm making a Safari extension for the first time. I want to enable my toolbar button only when the current page has a .gif open. How do I write my validate function for this?
Also, is the "validate" event fired every time the page reloads? Are there other triggers for it?
You can't be sure that the content of the current page is a GIF, but you can check whether the URL of the current tab ends with ".gif". In a global page script, use safari.application.activeBrowserWindow.activeTab.url to get the current URL.
In addition, you can use an injected script to inspect the DOM of the page. In Safari, if a document's body has a single node, and that node is an <img>, then the resource located at the tab's URL is probably an image. Use document.body.childNodes to check the body contents.
Validate events happen whenever Safari thinks you might want to update an extension element (like a toolbar button). This includes when a tab is opened, closed, focused, or blurred; when its URL is changed; and when its contents are reloaded. BTW, tab focus and blur happens also when Safari itself is focused or blurred, not just when you switch tabs.

Why doesn't XUL load handler work?

In Firefox dev tools, it seems the XUL iframes won't fire after the initial onload. For example, see the bottom of this file, where the extension makes the selected element in the inspector more easy to see. This is working when you open the inspector, but when you click to another page it reverts to the old inspector tree style. I even tried frame.contentWindow.addEventListener('load',styleit);, but it doesn't fire when a link is clicked on the web page, and page has loaded.
a) get a reference of the InspectorPanel object
b) listen for the ready event
var ip = window.ownerDocument.defaultView.inspector;`
ip.on("ready", styleit)

window.open(....) getting blocked in some browsers

I have a script where it opens a window for online application after executing some other scripts.
window.open() is not called on any click. It is getting called in a script and browser prevents the new window from appearing.
How to overcome this?
Here is the code:
window.open('/search/applyonline?jobid=".$jobDetails->getIdjob()."',
'applyurljob',
'height=550,\
width=800,\
toolbar=no,\
directories=no,\
status=no,\
menubar=no,\
scrollbars=yes,\
resizable=yes,\
left=200,\
top=250')
Popup blockers will block windows from being opened that are not in response to a click event. Therefore you can:
Ask your users to turn off their popup blocker (not nice).
Change your scripts to work in response to a link or button click.
Use fake windows such as a jQuery UI dialog.

Categories

Resources