How to open local files from firefox extensions in browser? - firefox-addon

I am trying to show downloaded files in the browser and it's working in chrome from chrome extension.
I want to open up to folder as in ss.
Working result in chrome looks like this:
Code used to open local file in chrome is:
chrome.tabs.create({
url: localFileUrl,
index: baseTab.index + 1,
});
eg: localFileUrl= "file:///C:\Users\Dell\Downloads\test"
From the Firefox extension I have used following code to open local
files in the new tab:
browser.tabs.create({
url: localFileUrl,
index: baseTab.index + 1,
}).then(res=>{
console.log(res);
}).catch(err=>{
console.log(err)
});
and in the console I get the error like this..
How can I open local files in Firefox from extension same like in chrome from chrome extension?!
I have added permissions tabs and activeTab in manifest.json file.

Related

OpenLayers: Loading a TileJSON from a local file

I'm trying to implement a local copy of a TileJSON in an iOS app through Cordova. The issue I'm having is that OpenLayers doesn't seem to recognise the JSON file as valid and thus doesn't show any tiles. I have tried local and remote versions of the same TileJSON and looked at the Console Logs, the local one has a status of "error" (but no explanation as to what that error might be...).
I think the issue is down to the fact that the JSON file is being loaded using a file: URL, rather than http:. I have put the JSON file on a remote server and this not only loads fine but actually loads the tiles from the local path.
Can OpenLayers be tricked into accepting the local file as a valid JSON file? Can Cordova be forced to load local files via HTTP? I think either of these options would fix the issue.
Thanks
EDIT: Here's the code I'm using to load the TileJSON:
var mapLayer = new ol.layer.Tile({
source: new ol.source.TileJSON({
url: getPhoneGapPath() + 'tiles.json',
crossOrigin: 'anonymous'
})
});
this.map.addLayer(mapLayer);
function getPhoneGapPath() {
var path = window.location.pathname;
path = path.substr( path, path.length - 10 );
return path;
}
The getPhoneGapPath() function is used to get the path to the webroot of the Cordova app.
This is probably related to a bug in OpenLayers, https://github.com/openlayers/ol3/issues/5647. The fix will be in the next release.
Also make sure that you configure Cordova to allow access to file:// urls when the application is served from a file:// url. The equivalent option in Chrome is --allow-file-access-from-files.

Console.log does nothing in console on Firefox

I found several threads about console.log not working on certain browsers couple years ago, I guess the issue should be solved today. Yet the following code doesn't display anything in Firebug's "console" tab (FF 43.04):
if (window.console) console.log( 'changed' );
Any idea why?
EDIT: no output, no error. This code was added inside .on( 'change', 'input:radio', function() { }); which fires when $( 'input[value="whatever"]' ).change(); runs.
You may try creating a file like a.html and placing it in your local IIS at c:\inetpub\wwwroot with contents:
<script>
if (window.console) console.log( 'changed' );
</script>
Then open debugger tools with CTRL+SHIFT+I, select console tab and then JS table. Open url http://localhost/a.html and it should work.
Firefox with console

Firefox Extension working locally, but not on another computer

I have a simple Firefox extension (taken from the docs), and when I run the extension on my the machine I built it on, everything works just as planned. But the moment I upload the file to Dropbox, download it onto another computer, and install it absolutely nothing happens. Both Fire Fox browsers are version 42.0, on Windows 7
var pageMod = require("sdk/page-mod");
pageMod.PageMod({
include: "*",
contentScript: 'document.body.innerHTML = ' +
' "<h1>Does this work?!</h1>";'
});

Firefox add-on works with "jpm run", but not whith .xpi file generated with "jpm xpi"

I'm using the Firefox Add-on SDK to develop a Firefox add-on.
I have followed the Getting Started tutorial.
Firefox version : 41.0.2
My Process is :
jpm run --> OK the add-on works fine
jpm xpi --> OK : Create #myAddon.xpi (JPM [info] Successfully created .xpi at ...)
Use of #myAddon.xpi --> NOK
When I tried to install the add-on in my Firefox ( Add-on -> install from file -> #myAddon.xpi ), I have a message "Install successfully". Looks good. BUT, the add-on doesn't work. Nothing happens.
So, why is the test with jpm run OK, but does not work after installing the .xpi file???
I can share the code with you, but how can this situation happen? If it works in test, I expect that it works in "release".
I get no error or warning.
High Level :
Index.js:
pageMod.PageMod({
include: "*",
contentScriptFile: [data.url("jquery-1.11.3.min.js"), data.url("./Compute.js")],
onAttach: function (worker) {
var currentUrl = tabs.activeTab.url;
param = currentUrl;
Request({
url: param,
onComplete: function (response) {
var parsed = JSON.parse(response.text);
worker.port.emit('got-request', parsed);
}
}).get();
}
data/Compute.js
self.port.on('got-request', function (data) {
console.log(data);
});
Edit (moved from comments):
I find something interesting.... Depending on the level of privacy in FireFox the addon will work or not. ( Options->Privacy->History "Remember history " or "Never remember history") - Remember history " --> addOn OK - "Never remember history" --> addOn NOK Any idea why
As you have determined, if you desire your Firefox Add-on SDK add-on to work in Private Browsing mode you need to have add the key private-browsing with a value of true in your package.json file.
If you are using no other permissions, you could add a line to your package.json file that looks like:
"permissions": {"private-browsing": true}
The Firefox documentation on writing SDK add-ons for private browsing mode specifically states that the require("sdk/private-browsing").isPrivate() method will return true when any of the following is the case (emphasis mine):
a private window, or
a tab belonging to a private window, or
a worker that's associated with a document hosted in a private window
any window, tab, or worker if the browser has been configured to never remember history (Options->Privacy->History)
If you do not have "private-browsing": true, then, as the documentation states, the following will be the case (emphasis mine):
the windows module will not list any private browser windows, generate any events for private browser windows, or let the add-on open any private browser windows
the tabs module will not list any tabs that belong to private browser windows, and the add-on won't receive any events for such tabs
any ui components will not be displayed in private browser windows
any menus or menu items created using the context-menu will not be shown in context menus that belong to private browser windows
the page-mod module will not attach content scripts to documents belonging to private browser windows
any panel objects will not be shown if the active window is a private browser window
the selection module will not include any selections made in private browser windows
The net effect will be that your add-on will appear to not work when the profile you are using is configured to never remember history without having the "private-browsing": true permission in your package.json.
If you do put that permission in your package.json file, you must use the private-browsing module, require("sdk/private-browsing").isPrivate(object), to check for being in a private window or tab. If you are in such a window or tab you need to not store any information about such environment.

Is it able to test PhoneGap File API with Ripple emulator

I am working on an application with PhoneGap (now Apache Cordova, with the version of 2.0), and using the PhoneGap File API to write file.
The File API I use could be referenced at:
http://docs.phonegap.com/en/2.0.0/cordova_file_file.md.html#File
I use Ripple Emulator (0.9.9beta) from here: https://developer.blackberry.com/html5/download to test my application in chrome.
But I find Ripple could not handle the PhoneGap File API correctly.
For example:
I want to create a file (root/foo.json) at the PERSISTENT directory
function onSuccess(fileSystem) {
fileSystem.root.getDirectory("dir", {create: true}, function(dirEntry){
dirEntry.getFile("foo.json", {create: true}, function(fileEntry){
fileEntry.createWriter(function(writer){
writer.write(JSON.stringify(fooData));
}, onfail);
}, onfail);
}, onfail);
}
function onfail(error)
{
console.log(error.code);
}
// request the persistent file system
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onSuccess, onfail);
It works fine on iOS simulator, which did create the right file at the right place, but in the Ripple Emulator running in chrome, I just got a onfail callback, and got error code 10 (FileError.QUOTA_EXCEEDED_ERR).
I also found someone with the similar question here: Is it able to test phonegap application outside emulator?
But still no answer.
Does Ripple emulator currently not work correctly for PhoneGap API? Or did I missed some setting?
Problem found. I need to grant quota before using the PERSISTENT filesystem object.
https://developers.google.com/chrome/whitepapers/storage#persistent
// Request Quota (only for File System API)
window.webkitStorageInfo.requestQuota(PERSISTENT, 1024*1024, function(grantedBytes) {
window.webkitRequestFileSystem(PERSISTENT, grantedBytes, onInitFs, errorHandler);
}, function(e) {
console.log('Error', e);
});
It seems Ripple-UI didn't do this for me (I checked the source code at lib/ripple/fs.js) . That's why I always get a FileError.QUOTA_EXCEEDED_ERR.

Resources