I'm using
chrome.tabs.onUpdated.addListener(function(){ });
on chrome, but it dos not work on Firefox, I have seen
browser.tabs.onUpdated.addListener(listener[, extraParameters])
on Firefox documentation, but I'm not sure how to use it, can someone give me an example?
chrome & browser API
You can use both chrome.* and browser.* API in Firefox.
chrome.* returns a callback function (although that is due to change to support Promise in manifest v3).
browser.* returns a Promise.
In case of *.addListene(), they always return a callback function.
Therefore, in Firefox the following are similar (and you can use either).
chrome.tabs.onUpdated.addListener(function(){
// do something
});
browser.tabs.onUpdated.addListener(function(){
// do something
});
browser.tabs.onUpdated.addListener() in Firefox can also have optional extraParameters but from your example it seems you might not need it.
ref:
chrome.tabs.onUpdated
browser.tabs.onUpdated
Related
Starting with iPhone OS 11.3, my app is broken with the following error:
SecurityError: Blocked attempt to use history.replaceState() to change session history URL from file:///var/containers/Bundle/Application/E73A3E4A-D961-4943-BAA3-7845E755F6A0/myplaceonline.app/www/index.html#/?phonegap=true to https://myplaceonline.com/?phonegap=true. Protocols, domains, ports, usernames, and passwords must match.
url:
file:///var/containers/Bundle/Application/E73A3E4A-D961-4943-BAA3-7845E755F6A0/myplaceonline.app/www/js/jquery.mobile-1.4.5.min.js
line #: 3 (31672)
The way I've always done it (and this continues to work with Android):
PhoneGap app loads JQM in an index.html page.
A JQM mobileinit event handler is attached which registers a pageloaded event handler which ultimately calls loadHomepage.
loadHomepage sets $.mobile.path.documentBase and the href attribute of the base tag to my remote server (https://myplaceonline.com/) and calls $.mobile.pageContainer.pagecontainer("change", "/", { allowSamePageTransition: true, transition: 'none', reloadPage: true, changeHash: true }); to load the remote homepage.
This ultimately drives JQM to call replaceState which fails with the security error:
replaceState#[native code]
squash#file:///var/containers/Bundle/Application/E73A3E4A-D961-4943-BAA3-7845E755F6A0/myplaceonline.app/www/js/jquery.mobile-1.4.5.min.js:3:31672
go#file:///var/containers/Bundle/Application/E73A3E4A-D961-4943-BAA3-7845E755F6A0/myplaceonline.app/www/js/jquery.mobile-1.4.5.min.js:4:322
navigate#file:///var/containers/Bundle/Application/E73A3E4A-D961-4943-BAA3-7845E755F6A0/myplaceonline.app/www/js/jquery.mobile-1.4.5.min.js:4:1598
The purpose of all of the above is so that I don't navigate away from file:/// because if I were to do that, I would lose access to all native phone JS APIs through PhoneGap. This works on older versions of iOS and continues to work on Android.
Any ideas on an alternative way to do this to get around the tighter security on newer versions of iOS? Alternatively, I see there are issues like https://github.com/jquery/jquery-mobile/issues/5465 which suggest a method of disabling history and I'm wondering if this would be another workaround and what I would lose?
Adding the following code to a mobileinit handler fixes the issue:
$.mobile.hashListeningEnabled = false;
$.mobile.pushStateEnabled = false;
$.mobile.changePage.defaults.changeHash = false;
I'm writing a new add-on as a Web Extension. In my package.manifest, I have the options_ui set:
"options_ui": {
"page": "options.html"
}
But in about:addons, the options button is not present.
So I tried to call the page directly from my background script:
runtime.openOptionsPage();
But I get this error:
Message: ReferenceError: runtime is not defined
Same error type with:
chrome.runtime.openOptionsPage();
Message: ReferenceError: chrome is not defined
I'm probably missing something very obvious there. I tested with Firefox ESR 45.0.4 and the latest Firefox Dev edition (51.0a2). How can I get the options page to show in about:addons and how can I call it from my background script?
It's browser.runtime.blah or chrome.runtime.blah.
I'm not sure if ESR 45 supports it.
This code should go in you background script right?
Please post more of your code so i can update my answer.
It turns out that I was mixing Web extensions with Add-on SDK
I am working on a firefox plugin that uses firebreath framework. The plugin checks whether the firebreath dll is registered using the following code.
if(document.getElementByID("dllID").valid)
{
alert("Dll registered");
}
else
{
alert("Condition failed");
}
The code works fine for firefox upto version 28.
For higher versions the condition always fails. Can anyone help me in this??
I've never heard of the valid attribute. What are you trying to accomplish exactly? If it is for form validation, you probably need to deal with validation objects https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms/Data_form_validation#The_HTML5_constraint_validation_API
if (document.getElementbyID("dllID").validity.valid){
...
} else {
....
}
Whats more, is this api seems to be present in FF29+ so it probably deprecated the plain valid attribute you are used to
Try .hasAttribute, .getAttribute, and .setAttribute
document.getElementByID("dllID").hasAttribute('valid')
Without these, is usually for XBL properties but things like id work too.
Im trying to create an extension that will interacts with github.
I need to use "eval" in my code but im keep getting blocked by the page CSP.
This is a simplified version of my code:
const pageMod = require("sdk/page-mod").PageMod;
var contentScript = 'try {eval("console.log(\'hello from eval\')");} catch (e) {console.log("page mode " + e.message);}';
pageMod({
include: "*",
contentScript: contentScript ,
contentScriptWhen: "start"
});
Can someone help me solve the problem?
This because the Content Security Policy: https://developer.mozilla.org/en-US/docs/Security/CSP/CSP_policy_directives
Usually 99% of the time, the usage of eval can be replaced with something else. If you give the context (why you need the eval), we can try to suggest an alternative.
That's the easy way.
The hard way, is intercept the response from github, to remove that header, using the observer notification "http-on-examine-response", here there is a full example but you can probably have a simplified version of it.
Personally, I would try to avoid using eval, it's usually easier.
I am working on a web app based on Sproutcore 1.9.1. To retrieve data from server it
makes a SC.Request.getUrl() request, which works fine in all the browsers except IE8.
For IE8 when the request is like this:
SC.Request.getUrl("'http://example.com/some/path')
.set('isJSON', YES)
.async(false) // made async false to work in IE
.notify(this, 'someMethodDidComplete', { query: query, store: store})
.send();
works fine. But when the request is :
SC.Request.getUrl("'http://example.com/some/path')
.set('isJSON', YES)
.notify(this, 'someMethodDidComplete', { query: query, store: store})
.send();
it works fine for other browsers but for IE8, it is not working. After spending some
time with the issue i found out that the finishrequest() is not invoking. For doing so
what I did is made 'asynchronous false' and then it works. Now I don't know what to do.
Please suggest me something on this and why normal request is not working.
thanks in advance.
This problem is known (https://github.com/sproutcore/sproutcore/issues/866) and seems to be fixed, at least on SC master.
As a side note, you include the query and store in an object as parameter to .notify(). You don't need to do this, you can simply include them as extra parameters and your notify function will be called with those extra parameters:
.notify(this,this.notifier,query,store)
and somewhere else in the file:
notifier: function(result,query,store){ }