How would one display a prompt after installation of an extension? - firefox

When my add-on installs it needs to prompt the user to get a username or something like that. After that it stores it and shouldn't ask again. Where would I place this prompt? install.rdf? browser.xul?

There is no explicit mechanism to run code when the extension installs - you should simply do it when your extension runs for the first time. The easiest approach would be checking whether the user name is already set up. If it is not - show the prompt.
It is not recommended to show a modal dialog, those are extremely annoying to users, especially when they suddenly appear during Firefox start-up. You should instead open your page in a tab. A slight complication: Firefox might be restoring a previous session when it starts up. If you open your page too early the session restore mechanism might replace it. So you should wait for the sessionstore-windows-restored notification, something like this should work:
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
var observer = {
observe: function(subject, topic, data)
{
Services.obs.removeObserver("sessionstore-windows-restored", this);
var browser = window.getBrowser();
browser.loadOneTab("chrome://...", {inBackground: false});
},
QueryInterface: XPCOMUtils.generateQI([
Components.interfaces.nsIObserver,
Components.interfaces.nsISupportsWeakReference
])
};
Services.obs.addObserver("sessionstore-windows-restored", observer, true);
A final complication is that your code is probably running from a browser window overlay - meaning that there will be multiple instances of your code if the session restored contains more than one window. You probably want the code above to run only once however rather than opening your first-run page in every browser window. So you will have to coordinate somehow, maybe via preferences. A slightly more complicated but better solution would be having a JavaScript code module in your extension - code modules are only loaded once so you wouldn't have a coordination issue there.

Try using an addonlistener https://developer.mozilla.org/en/Addons/Add-on_Manager/AddonListener#onInstalling%28%29
Or by using the preferences: https://stackoverflow.com/a/958944/1360985

Related

How to force Firefox session to save?

I'm trying to troubleshoot some bug in FF.
At some point after start (usually some days) when I try to open new tab, it does, bot in a wierd state: it does not takes focus and I can't click it. And one more side effect (altough it may be unrelated): it stops updating sessionstore file. If I try to restart browser, it crushes and on the next launch it opens about:sessionrestore page with outdated tabs.
So I want to find a way to force sessionstore update logic to execute on its own.

Selectors only work when webpage is opened in Internet Explorer

I created a login sequence and my selectors for the input email, password, click login and element exists are valid. But only when I have the Internet Explorer page open on the website I'm working with.
I did that sequence again, and I ran it, initially it worked but when I ran the hole project it broke again, I tried "repair" and "indicate", I tried to eliminate the title but nothing is working.
As far as I can see, you are using selector attribute:
"title=ACME System 1 - Dashboard"
Try using a wildcard: title='ACME System 1*', so it can work when you leave the dashboard.
This worked for me when I took those UiPath Academy courses.
In order to automate tasks within a browser with UiPath, the browser must be open. There is an activity called Open Browser that's included in the default activities for every project. You need to add this activity to the beginning of your sequence and pass in the appropriate parameters, (ie. URL, browser type) you can then pass the outputted browser variable to an attach browser sequence and execute your browser automation acivities within that.
Browser activity sceenshot
In addition, the selector that you have shared does not look like a stable selector. There may be other 'H1' elements on the screen that will cause your automation to fail. I would use the UI explorer to help you build a better, more stable selector.
Did you initially use IE to indicate screen elements and then changed the BrowserType property to use a different browser? Please share the sequence to suggest you a fix for your issue.
I would also suggest you to modify the selector to 'title='ACME System *'.
In order for selector to work the application needs to be open and the desired element needs to be available. So when you close the browser the selector disappears.
You may consider swithching to 'Modern Design Experience' and use 'Use Application/Browser' scope to make this more intuitive, and it will also automatically open the browser for you if it is closed.

Firefox extension - Share common state between two or more windows

I am developing firefox extension.
Problem is that when i open second window (Ctrl + N) my extension has new state for new opened window.
If I reacts or changes on second window it never affect on first window or vice versa.
Ex
Installed extension on Firefox
first window opened. My extension proper functioning, change state, login, view data etc
then opened second. My extension goes new state I cant get previous states (first window states).
How can maintain same state between first and second or other firefox opened windows.?
Am I correct to assume you're developing a XUL overlay add-on, and not an SDK add-on?
One way to share state between windows is to use Javascript code modules. A code module will only be loaded once (unless explicitly unloaded) and therefore will expose the same data to multiple windows. Be sure to read the "Sharing objects using code modules"., However, please note that therefore when closing a window, any state associated with it and stored within the code module must be cleaned up, or would leak otherwise.
If you're using the SDK instead, your main.js module is already the equivalent of a code module. Content scripts may use message passing to store and retrieve state from your module.

Disable/Change Firefox Safe Mode Hotkey (Shift)

Is there any way to change the firefox shift hotkey that makes firefox start in safe mode? I've set up some unit tests using Selenium and PHPUnit, but if I'm working on the machine while the tests are running then I frequently find I'm pressing shift as I type (holding shift as I select blocks of code is another big offender). This causes the test to fail (and time out) even if you click past the safe mode prompt that pops up.
Is there a way to disable this hot key, or change the key to something that I'd use less often?
I've also met with this problem and didn't find a solution. It seems that it is still an open issue: Mozilla Forums thread, Bug 653410, Bug 644175 and so on. As a workaround you can install firefox 3.6 as this feature was implemented since firefox 4, but probably this will not suite you.
Mozilla finally added an environment variable to control this behavior. Unfortunately, configuring this environment variable in a way that applies to the overall graphical system, rather than merely a bash session, is a bit difficult. This used to be done via /etc/launchd.conf, but macOS dropped support for this in v10.10. Fortunately, systemctl offers a .plist file system which can define run programs and define system-wide environment variables at boot, so I published this working .plist file, with instructions for installing and removing it:
https://github.com/mcandre/dotfiles/blob/master/setenv.MOZ_DISABLE_SAFE_MODE_KEY.plist
This is awesome for me, because I like to launch my web browser from anywhere in the GUI with Control+Alt+G via QuickSilver, which of course includes the Alt modifier that Firefox tends to interpret as signaling safe mode.
Until Bug 653410 is fixed, the best workaround I can come up with is to detect when safe mode is launched and handle it in the best way fit for your particular purposes. This may mean killing the Firefox process and launching again, or it may mean warning the user, or both. When Firefox is launched into safe mode, it writes "LastVersion=Safe Mode" to its compatibility.ini file in its profile directory. An example C# function to watch for this is given below.
FileSystemWatcher safeModeWatcher;
private void watchSafeMode()
{
string profiles = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Mozilla", "Firefox", "Profiles");
string defaultProfile = Directory.GetDirectories(profiles, "*default*")[0];
safeModeWatcher = new FileSystemWatcher(defaultProfile, "compatibility.ini");
safeModeWatcher.NotifyFilter = NotifyFilters.LastWrite;
safeModeWatcher.Changed += delegate(object s, FileSystemEventArgs e)
{
if (File.ReadAllText(e.FullPath).Contains("LastVersion=Safe Mode"))
{
// safe mode!
System.Diagnostics.Trace.WriteLine("safe mode detected!");
// TODO kill Firefox and launch again, or whatever makes sense for you
}
};
safeModeWatcher.EnableRaisingEvents = true;
// ...
// TODO Dispose safeModeWatcher when done
}

Start Internet Explorer 8 in a separate process using vbscript

Due to the recently added "feature" in IE8 where new windows are automatically associated with a single session, some of our code is behaving erratically.
This is because a separate app would launch a new IE window when it was activated, and once the user was finished, close the window. This worked fine in IE7 because the session information in the windows stayed separate. However in IE8, since the session is shared among IE windows, we find that the "pop up" app would corrupt the session on the first app.
I have read about the nomerge switch, so that is a workaround, but I was wondering if there was a way of working the solution into the "CreateObject" of vbscript; i.e:
Dim ieWin As Object
Set ieWin = CreateObject("InternetExplorer.Application")
Is there a way of sending parameters when calling the CreateObject function?
No, there's no way to use COM to create an IE instance that specifies this behavior (or any of the others, e.g. InPrivate, No Add-ons, etc). The only thing you can do is create an automation instance that defaults to MediumIL using the CLSID provided for that purpose. http://blogs.msdn.com/b/ieinternals/archive/2011/08/03/internet-explorer-automation-protected-mode-lcie-default-integrity-level-medium.aspx
If you have control over the web application you are loading with your IE window you can set it's session to "cookieless" (http://msdn.microsoft.com/en-us/library/aa479314.aspx) which will avoid the issues you're having with multiple instances.
The solution we ended up going with, although it's more a work around than anything else - was assigning a new url to the popped up window.
Previously, it worked as follows:
Call centre agents would be using our internal app for other duties
e.g. "http://internalsite/somepage.faces" on a day to day basis.
When they got a phone call, a third party app would fire up
"http://internalsite/customerdetails.faces". This caused the issues mentioned above.
The solution we went with:
We assigned "http://internalsite/customerdetails.faces" it's own url e.g."http://customerdetailminisite/customer.faces".
This way the call center agent could keep their main window open for other stuff and still be able to handle calls when they came in.

Resources