I have a old addons to Firefox that registry a custom protocol "linkpassword://"
Since Firefox Version 57 the addon stop working and I have to rewrite the full addons as a Firefox WebExtenstion.
My issue is I can't find a way to registry a handler for protocol "linkpassword://".
The "protocol_handlers" section in the manifest.json of your Firefox WebExtensions can be used to register a common or a custom protocol handler.
But from the documentation at MDN WebExtensions protocol_handlers it seems like you have to prefix a custom protocol handler with web+something or ext+something.
You can process the link in your extension by just using a page in your extension as "uriTemplate" like this:
"protocol_handlers": [
{
"protocol" : "ext+linkpassword",
"name" : "Password Link",
"uriTemplate": "html/processLink.html#login=%s"
}
],
Currently, you can't register a handler for linkpassword:// with WebExtensions.
As for now only the specified whitelisted protocols are allowed to be used without a prefix (one of bitcoin, geo, gopher, im, irc, ircs, magnet, mailto, mms, news, nntp, sip, sms, smsto, ssh, tel, urn, webcal, wtai, xmpp). Any other custom name requires to be prefixed with either web+ or ext+. See protocol_handlers reference.
With the prefix you can register it this way:
"protocol_handlers": [
{
"protocol" : "ext+linkpassword",
"name" : "Password Link",
"uriTemplate": "html/processLink.html#login=%s"
}
],
Then you'll have to use ext+linkpassword:// in your links to trigger the handler.
While with the current state of WebExtensions you can't set a handler for an arbitrary protocol, like linkpassword://, it is likely to change at some point, since there are some discussions about it, but it's hard to say when to expect this. As a temporary workaround before the real solution is available you can patch linkpassword:// to ext+linkpassword:// on the web page with your WebExtension JS code so that the handler is still triggered even if the links on the page were loaded with the linkpassword:// schema.
Related
trying to create a extremely simple chrome extension, but need some help.
Purpose: When I click the extension icon, URL of existing tab must be forwarded to telegram. This can be done via a HTTPS call like https://api.telegram.org/bot123456:xxxxxxxxxxxxxxxxxxxxxx/sendMessage?chat_id=12345678&text=https://activetab.url
Single extension button, when clicked:
Grab URL of active link
Post http enriched with link url grabbed in previous step
No security concerns, I want to install the extension in developer mode only in my own browser.
Goldplated option would be to let the user specify the bot, the token & recipient id in settings of the app.
Thx for any feedback
It should only take a few lines of code.
I assumed that the http request is of type: "GET".
If not, you have to modify the fetch command according to Telegram specifications.
//manifest.json
{
...
"background": {
"service_worker": "background.js"
},
"action": {
"default_icon": { // optional
"16": "images/icon16.png", // optional
...
},
"default_title": "Click Me" // optional
},
"permissions": ["tabs"]
...
}
//background.js
chrome.action.onClick.addListener(t => fetch('https://api.telegram.org/bot123456:xxxxxxxxxxxxxxxxxxxxxx/sendMessage?chat_id=12345678&text=' + tab.url))
We want to serve a Docusaurus-build with Electron.
For this we are using a custom protocol that just serves the files to the Electron-Browser.
The Problem is, the Javascript that is running in the static-html build of the Docusaurus app just wont accept the url (at least that is what we think)
If we serve "doc://doc/docs/intro/index.html" it pops up for a second and afterwards the "Page Not Found"-page is shown - because the javascript does that.
Our url is "doc://doc" and our baseUrl is "/" and we can not figure out how to stop the Javascript from chaning the currently loaded page to the Page not found one.
(We disabled the Javascript and if it is disabled that error does not appear)
The problem was Electron...
You have to give the custom protocol privledge with this:
protocol.registerSchemesAsPrivileged([
{
scheme: 'doc',
privileges: { secure: true, standard: true },
},
]);
So it has actually nothing to do with Docusaurus.
I am trying to find the active tabs across all windows, actual query and action is more detailed but this demonstrates the basic problem
chrome.tabs.query({active: true}, function (tabs) { console.log(tabs); });
It seems that with Chrome and Firefox we can use that api with either activeTab or tab permission, only limitations on the search items such as url.
The chrome.tabs or browser.tabs docs only seem to indicate tab permission for some parts.
When using only activeTab permission MS Edge throws error, Chrome gives the result
Adding tabs permission and I can get the results in MS Edge
Is this a deliberate difference, or a bug, or doing something else incorrect?
Trying to ask for minimal permissions as Mozilla and Google required validation of usage with permissions with wide access.
similar to, but not the same as Why browser.tabs.query is not working in Edge Extension ?
first of all, you have to add 'tabs' permission to your manifest file like this
"permissions": [
"tabs"
]
and next use this code
let queryOptions = {
active: true,
currentWindow: true
};
chrome.tabs.query(queryOptions,function (tabs){
alert(tabs[0].url)
});
after that just remove the old extension and load new files in your extensions then observe the permission section in extension details it's should be changed and check it out.
So I'm using the 'google-api-client' gem with Rails, and I'm attempting to call the URL below in order to get video views by day and insightTrafficSourceType. This is a call that appears to be allowable from the Available Reports documentation page.
Additionally, I found that I was able to make this call by using the API Explorer tool provided by Google.
URL:
https://www.googleapis.com/youtube/analytics/v1beta1/reports?metrics=views&ids=channel==CHANNEL_ID&dimensions=day,insightTrafficSourceType&filter=video==VIDEO_ID&start-date=2013-01-15&end-date=2013-01-16&start-time=1970-01-01
Result:
{
:error=>
{
"errors"=>[
{
"domain"=>"global",
"reason"=>"invalid",
"message"=>"Unknown identifier (insightTrafficSourceType) given in field parameters.dimensions."
}
],
"code"=>400,
"message"=>"Unknown identifier (insightTrafficSourceType) given in field parameters.dimensions."
}
}
I'm not sure what extra data I can provide in the initial description of this bug, but as stated before I am making the call to the API with the Google::APIClient Ruby library. The actual code itself looks like this:
client.execute(
:api_method => api.reports.query,
:parameters => options
)
You are still referencing the old beta API, i.e., in your URL, you have 'v1beta' and you should have 'v1' there. Try replacing that and running it again. Also, you can look at the api explorer to see the exact URL that should be generated in live examples with your acct (once you enable OAuth) here:
https://developers.google.com/youtube/analytics/v1/
(Look at the bottom of the page.)
Finally, start-time isn't a parameter listed on the production version of the API, so you will want to remove that as well.
I want to prefix URLs which match my patterns. When I open a new tab in Firefox and enter a matching URL the page should not be loaded normally, the URL should first be modified and then loading the page should start.
Is it possible to modify an URL through a Mozilla Firefox Addon before the page starts loading?
Browsing the HTTPS Everywhere add-on suggests the following steps:
Register an observer for the "http-on-modify-request" observer topic with nsIObserverService
Proceed if the subject of your observer notification is an instance of nsIHttpChannel and subject.URI.spec (the URL) matches your criteria
Create a new nsIStandardURL
Create a new nsIHttpChannel
Replace the old channel with the new. The code for doing this in HTTPS Everywhere is quite dense and probably much more than you need. I'd suggest starting with chrome/content/IOUtils.js.
Note that you should register a single "http-on-modify-request" observer for your entire application, which means you should put it in an XPCOM component (see HTTPS Everywhere for an example).
The following articles do not solve your problem directly, but they do contain a lot of sample code that you might find helpful:
https://developer.mozilla.org/en/Setting_HTTP_request_headers
https://developer.mozilla.org/en/XUL_School/Intercepting_Page_Loads
Thanks to Iwburk, I have been able to do this.
We can do this my overriding the nsiHttpChannel with a new one, doing this is slightly complicated but luckily the add-on https-everywhere implements this to force a https connection.
https-everywhere's source code is available here
Most of the code needed for this is in the files
IO Util.js
ChannelReplacement.js
We can work with the above files alone provided we have the basic variables like Cc,Ci set up and the function xpcom_generateQI defined.
var httpRequestObserver =
{
observe: function(subject, topic, data) {
if (topic == "http-on-modify-request") {
var httpChannel = subject.QueryInterface(Components.interfaces.nsIHttpChannel);
var requestURL = subject.URI.spec;
if(isToBeReplaced(requestURL)) {
var newURL = getURL(requestURL);
ChannelReplacement.runWhenPending(subject, function() {
var cr = new ChannelReplacement(subject, ch);
cr.replace(true,null);
cr.open();
});
}
}
},
get observerService() {
return Components.classes["#mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
},
register: function() {
this.observerService.addObserver(this, "http-on-modify-request", false);
},
unregister: function() {
this.observerService.removeObserver(this, "http-on-modify-request");
}
};
httpRequestObserver.register();
The code will replace the request not redirect.
While I have tested the above code well enough, I am not sure about its implementation. As far I can make out, it copies all the attributes of the requested channel and sets them to the channel to be overridden. After which somehow the output requested by original request is supplied using the new channel.
P.S. I had seen a SO post in which this approach was suggested.
You could listen for the page load event or maybe the DOMContentLoaded event instead. Or you can make an nsIURIContentListener but that's probably more complicated.
Is it possible to modify an URL through a Mozilla Firefox Addon before the page starts loading?
YES it is possible.
Use page-mod of the Addon-SDK by setting contentScriptWhen: "start"
Then after completely preventing the document from getting parsed you can either
fetch a different document from the same domain and inject it in the page.
after some document.URL processing do a location.replace() call
Here is an example of doing 1. https://stackoverflow.com/a/36097573/6085033