Firefox addon SDK, open an url automatically after Firefox startup? - firefox

With Firefox addon SDK, how to open specific url automatically after Firefox startup (for the purpose of testing page)
I've tried tabs.open(url) in this doc:
var tabs = require("sdk/tabs");
tabs.open("http://www.example.com");
And this one and a lot of Stackoverflow page ..., but none of them works at all...(It is still just a blank tab after $ cfx run)

I think you want to do this:
const tabs = require('sdk/tabs');
exports.main = function (options, callbacks) {
if (options.loadReason === 'startup') {
tabs.open('https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Listening_for_load_and_unload');
}
};
The documentation for this is located here:
https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Listening_for_load_and_unload

#canuckistani is actually right: if you're not seeing it, it's probably because your options.loadReason is something else. If you've got the plugin installed already, for example, you would get loadReason upgrade instead when you try to install the plugin again. See that url #canuckistani gave for more info.

Related

Is there a platform-independent method for opening links in an Outlook-addin?

I have an outlook-addin written in Angular framework, which communicates with the Outlook through the office-js.
My goal is to implement a service that opens any kind of URLs/links in any mainstream platforms where outlook is available, to be specific: in Google Chrome, Safari, Firefox, Opera, Internet Explorer, The MacOS desktop Outlook - old and new versions either, and most of the Windows desktop Outlook versions (2016, 2019, O365). But unfortunately I can not find a way that works in all of the platforms, and I want to avoid implementing it in a platform-dependent manner.
The first problem I encountered with, is that when I am trying to open links by a simple js function window.open(url) then the outlook versions that use Internet Explorer as an engine are failing to open URLs that contain the character #. That is because IE does not seem to be able to read this character and it cuts the URL in half by the # character and it completely removes the parts followed by the #.
https://en.wikipedia.org/wiki/County_Antrim#/media/File:Ballycastle_Harbour_-_geograph.org.uk_-_468327.jpg
window.open(
"https://en.wikipedia.org/wiki/County_Antrim#/media/File:Ballycastle_Harbour_-_geograph.org.uk_-_468327.jpg",
"_blank"
);
For example, if I try to open the URL above on Windows outlook 2019 which uses Internet Explorer as it's engine, then the url will look like this in the end:
https://en.wikipedia.org/wiki/County_Antrim
For a solution I've implemented a workaround that encodes the URL by a built-in function that comes with typescript which allows the IE to be able to open the link. By simply passing the encoded URL to the window.open() does not work because it concatenates the url with the host of my addin, which results in an invalid link.
window.open(
encodeURIComponent(
"https://en.wikipedia.org/wiki/County_Antrim#/media/File:Ballycastle_Harbour_-_geograph.org.uk_-_468327.jpg"
),
"_blank"
);
The host of my addin + the encoded URL:
https://localhost.eu.ngrok.io/https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FCounty_Antrim%23%2Fmedia%2FFile%3ABallycastle_Harbour_-_geograph.org.uk_-_468327.jpg
So I had to redirect manually with a simple html code as shown below:
redirect.html:
<html>
<head>
<script type="text/javascript">
window.onload = function (event) {
var regex = /\?url=(.*)/ig;
var match = regex.exec(location.search);
if (match && match[1] && match[1] !== "") {
location.href = decodeURIComponent(match[1]);
}
else {
document.body.innerHTML = "Redirect failed!";
}
};
</script>
</head>
</html>
typescript code:
url = "https://en.wikipedia.org/wiki/County_Antrim#/media/File:Ballycastle_Harbour_-_geograph.org.uk_-_468327.jpg"
window.open("./redirect.html?url=" + encodeURIComponent(url), "_blank");
Unfortunately, this method also has some flaws in the desktop outlook of MacOS. Redirecting makes the links open in a simple webviewer of the outlook application, and not in Safari as it is expected since the default browser is set to Safari in both of the system preferences and in the outlook browser preference. Despite the fact that it can open the links in this webviewer, I can not use it, because some of the webpages I want to navigate to does not support to be opened by the webviewer.
I was suspecting that this behaviour is caused by the relativity of the url ("./redirect..."). So I have tried building the URL by adding dynamically or even hardcoding the host of my addin to the beginning of the URL this way:
`${window.location.origin + window.location.pathname}/redirect.html?url=` + encodeURIComponent(url);
But there was no difference in the results by doing it, so I am guessing that referencing the host of the addin itself does not change quality or state of the URL, meaning that it is still managed as a relative link.
Since I had the opportunity to host the redirect.html from another server, I have tried referencing the redirect.html file from another host, and that way even the MacOS Outlook worked perfectly, proving my suspicion of the wrong management of relative links.
I have also tried using the function called openBrowserWindow provided by office-js the following way:
Office.context.ui.openBrowserWindow(url);
But this was also a dead-end, since this could neither handle the # character in IE nor it was supported in all of the platforms I need to use.
The last workaround I have tried is by completely reworking the service and instead of opening the links by using js or ts functions, I have tried binding the urls to the href attribute of <a></a> elements, however the application requirements exclude this method, as there are some links that are expected to be opened by double clicking, which can not be done with using an <a> tag as far as I know, at least not in an "hacky" way.
Which I would really like to know, what makes the links open in the webviewer of the MacOS outlook application instead of the default browser of the system? Is it a setting I am missing, or is there a way to force using the safari?
Did you try simply doing:
if (Office.context.ui.openBrowserWindow) {
Office.context.ui.openBrowserWindow("https://google.com");
} else
{
window.open("https://google.com");
}
Since openBrowserWindow is selectively not supported in OWA, window.open will automatically take over.

Web-extension opening url on addon install works fine on Opera and Chrome but fails on Firefox?

The following web-extension code in my background script background.js works fine on Opera and Chrome triggering appropriate webpage on Install, Update and Uninstall but does nothing in firefox. The same is shown as compatible here - https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/runtime/onInstalled
Manifest.json has:
"background" : {
"scripts" : ["includes/background.js"]
},
background.js has :
//CHECK INSTALL, UPDATE, UNINSTALL
chrome.runtime.onInstalled.addListener(function (details) {
if (details.reason == "install") {
chrome.tabs.create({
url : "https://www.example.com/install.html"
});
}
if (details.reason == "update") {
chrome.tabs.create({
url : "https://www.example.com/update.html"
});
}
});
chrome.runtime.setUninstallURL("http://www.example.com/uninstall.html");
You have installed your add-on as a temporary add-on through about:debugging. The documentation states:
This event is not triggered for temporarily installed add-ons.
Thus, the event won't fire. You will need to install your add-on as a normal, non-temporary add-on. There are multiple ways for you to do so. The official way is to install Firefox Developer Edition, or Firefox Nightly and set xpinstall.signatures.required to false in about:config. If you want to do so in the release version of Firefox, you can entirely disable add-on signature checking in Firefox. The process to do so is described in the linked answer (also listed below). You may also the information in the Documentation link below helpful in installing your add-on as a normal add-on.
How can I disable signature checking for Firefox add-ons?
Installing add-ons for development (an archive of Stack Overflow Documentation)

Custom url protocol for OSX desktop app using electron by atom

I am new to dekstop app by electron. However i built a desktop app using this source code and just changing the links to my site. Now I have a functional desktop app for mac.
But i want to open my app using a link say appName://and-some-link-follows
How can i implement custom url schema to open dekstop app whenever i click appName://....
For example:
I want to do something like Slack desktop app which opens up by clicking slack://and-some-link
Any help please. Stuck here for 2 days. Thanks in advance.
Today I faced a similar thing and upon doing some researching, I found this useful tutorial on how to do it. It explains everything thoroughly and I think it might be useful for others facing the same issue. This is the highlights:
const electron = require('electron')
const protocol = electron.protocol
// handles links `todo2://<something>`
const PROTOCOL_PREFIX = 'todo2'
function createWindow () {
mainWindow = new BrowserWindow({width: 1000, height: 800})
protocol.registerHttpProtocol(PROTOCOL_PREFIX, (req, cb) => {
const fullUrl = formFullTodoUrl(req.url)
devToolsLog('full url to open ' + fullUrl)
mainWindow.loadURL(fullUrl)
})
}
Also there's a guide on how to build for both OSX and Windows at the end of the post I linked.
For those who'd like to read a bit more, here's a link to the official docs.
I found it.
Do a build for your app
Right click -> show package content
In info.plist add the following
Open app once to register customURL into system.
In terminal enter /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -dump|egrep "(bindings.*:$)"|sort to check wheather yours is in the list.

Updating Firefox addon jsm module code without browser restart

I am developing a Firefox addon that is loaded from a directory instead of an xpi, Firefox extension proxy file. The extension is based on jsm modules.
Is there a way to update those modules to reflect the code changes. The only way to do it now is to close and restart the browser but that its not a sane way to develop anything.
Tried to:
Components.utils.unload('resource://myextension/mymodule.jsm');
Components.utils.import('resource://myextension/mymodule.jsm');
but changes are not made.
Got the answer from Victor Porof. In order to make this work you need to clear first the cache:
var obs = Cc["#mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
obs.notifyObservers(null, "startupcache-invalidate", null);
Hope this helps anyone

Selenium IDE datadrivenv0.2 issue with Firefox 20.0

I have just updated my firefox to v 20.0. Whenever I open Selenium IDE in firefox , it show a popup error .
Failed to load user-extensions.js file=[PATH to file ...]datadriven_v0.2/datadriven.js lineNumber=37 error=ReferenceError:XML is not defined.
The reported line in the file is sth like this :
XML.serialize = function(node) {
if (typeof XMLSerializer != "undefined")
return (new XMLSerializer()).serializeToString(node) ;
else if (node.xml) return node.xml;
else throw "XML.serialize is not supported or can't serialize " + node;
}
I do not know any thing specific to selenium IDE ,if XML is part of Selenium IDE or firefox . However, it seems latest updates to Firefox has sth to do.
I ll appreciate if someone help me fix this issue.
You can fix this by declaring the XML-Object in datadriven.js before it is called.
var XML = {};
XML.serialize = function(node) {
if (typeof XMLSerializer != "undefined")
return (new XMLSerializer()).serializeToString(node) ;
else if (node.xml) return node.xml;
else throw "XML.serialize is not supported or can't serialize " + node;
}
I don't know if this has any side effects, but for me it works.
Sven's idea worked perfectly for me. I added the command
var XML = {};
to the beginning of my user-extensions.js file, closed FF and Selenium, and restarted them. They've been working perfectly since then. I'm up to FF v21.0 with no problems.
Thanks Sven!
I am posting this for anyone using sel-blocks; the above solutions don't seem to work, since sel-blocks is an add-on and not a user-extension. However, there is still a solution. I added the line suggested above:
var XML = {};
to this file instead:
xmlextras.js
This file can be found in (selenium extension folder)/chrome/content/selenium-core/scripts
If you aren't sure how to get to your selenium extension folder, roughly here is how:
C:\Users(your username)\AppData\Roaming\Mozilla\Firefox\Profiles(your firefox profile)\extensions{a6fd85ed-e919-4a43-a5af-8da18bda539f}
I apologize if I'm not using the correct format for posting an answer or anything, but I just want to make sure that anyone searching for the answer I was looking for is able to find something.
From checking the Selenium website, the latest version of SIDE only supports up to Firefox version 17.
https://code.google.com/p/selenium/wiki/SeIDEReleaseNotes

Resources