Since Firefox 19, there is an internal default PDF reader "pdf.js". How can I detect whether this is the reader by default?
This might be what you are looking for...
http://www.pinlady.net/PluginDetect/PDFjs/
This will test for it. I can't get to the other link due to corporate firewall. Dunno what it says. Maybe its the same.
FIDDLE HERE
<iframe src="some.pdf" id="iframe" name="iframe"></iframe>
.
// FireFox test for PDFJS to display PDFs. Works in 20 & 21.
// If you don't test for the browser ...
// IE says PDFJS is there. It isn't.
// Chrome hangs on the fiddle
// Safari for Windows says PDFJS isn't there
$(window).load(function() {
var userAgent = navigator ? navigator.userAgent.toLowerCase() : "other";
if(userAgent.indexOf("firefox") > -1) {
var $iframe = $("#iframe");
var $innerDiv;
try {
$innerDiv = $iframe.contents().find('div');
alert("PDFJS not loaded");
} catch (e) {
alert("PDFJS loaded");
}
} else {
alert("Not running in FireFox - no PDFJS available");
}
});
Related
How do I override Keyboard Shortcuts in Firefox so that it can be picked up by web page
For example, I have a webpage that detects ctrl-shift-h which worked fine in version 56 but now in version 96 it brings up a "Show All History" dialog
I am doing many such things so I looking for a generic way to override Firefox keyboard shortcuts
I found a way by adding two files under the Firefox directory
Firefox64\defaults\pref\config-prefs.js
pref("general.config.filename", "config.js");
pref("general.config.obscure_value", 0);
pref("general.config.sandbox_enabled", false);
Firefox64\config.js
let { classes: Cc, interfaces: Ci, manager: Cm } = Components;
const {Services} = Components.utils.import('resource://gre/modules/Services.jsm');
function ConfigJS() { Services.obs.addObserver(this, 'chrome-document-global-created', false); }
ConfigJS.prototype = {
observe: function (aSubject) { aSubject.addEventListener('DOMContentLoaded', this, {once: true}); },
handleEvent: function (aEvent) {
let document = aEvent.originalTarget; let window = document.defaultView; let location = window.location;
if (/^(chrome:(?!\/\/(global\/content\/commonDialog|browser\/content\/webext-panels)\.x?html)|about:(?!blank))/i.test(location.href)) {
if (window._gBrowser) {
let keys = ["key_find", "key_findAgain", "key_findPrevious", "key_gotoHistory", "addBookmarkAsKb", "bookmarkAllTabsKb", "showAllHistoryKb", "manBookmarkKb", "viewBookmarksToolbarKb", "key_savePage", "key_search", "key_search2", "focusURLBar", "focusURLBar2", "key_openDownloads", "openFileKb", "key_reload_skip_cache", "key_viewSource", "key_viewInfo", "key_privatebrowsing", "key_quitApplication", "context-bookmarklink"];
for (var i=0; i < keys.length; i++) {
let keyCommand = window.document.getElementById(keys[i]);
if (keyCommand != undefined) {
keyCommand.removeAttribute("command");
keyCommand.removeAttribute("key");
keyCommand.removeAttribute("modifiers");
keyCommand.removeAttribute("oncommand");
keyCommand.removeAttribute("data-l10n-id");
}
}
}
}
}
};
if (!Services.appinfo.inSafeMode) { new ConfigJS(); }
You can get a list of ids for the keys from the source by putting the following URL in your browser
view-source:chrome://browser/content/browser.xhtml
Sorry I can't comment yet but to extend zackhalil answer:
For those on Linux or simillar Unix/Unix-like systems replace Firefox64 for /usr/lib/firefox. Don't be confused with $HOME/.mozilla/firefox
On Mozilla Firefox version 26 bing maps doesn't work. I dosn't zoom and locate (and location service are enabled in firefox settings). In don't get any error or warning. In all other browsers (IE, Chrome...) all works fine. Where is problem?
It should work with Firefox 26 according to the supported browser information.
Firefox 3.6 and later
It works fine when I run it on Windows.
function GetLocation() {
if (!!navigator.geolocation) {
navigator.geolocation.getCurrentPosition(UpdateLocation, HandleErrors);
}
}
function UpdateLocation(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
setPushpin(longitude, latitude);
document.getElementById('longitude').value = longitude;
document.getElementById('latitude').value = latitude;
Microsoft.Maps.Events.addHandler(map, 'click', changePosition);
}
function HandleErrors(error) {
switch (error.code) {
case error.PERMISSION_DENIED: alert("user did not share geolocation data");
break;
case error.POSITION_UNAVAILABLE: alert("could not detect current position");
break;
case error.TIMEOUT: alert("retrieving position timed out");
break;
default: alert("unknown error");
break;
}
}
function setPushpin(longi, lati){
map.setView({ center: { latitude: lati, longitude: longi }, zoom: 16});
deletePushpin();
var newURL = window.location.protocol + "//" + window.location.host + "/";
var pushpin= new Microsoft.Maps.Pushpin(map.getCenter(), {icon:newURL+"images/marker.png", height:35, width:26});
map.entities.push(pushpin);
pushpin.setLocation(new Microsoft.Maps.Location(lati, longi));
}
function deletePushpin(){
for(var i=map.entities.getLength()-1;i>=0;i--){
var pushpin= map.entities.get(i);
if (pushpin instanceof Microsoft.Maps.Pushpin){
map.entities.removeAt(i);
}
}
}
changePosition = function (e) {
if (e.targetType == "map") {
var point = new Microsoft.Maps.Point(e.getX(), e.getY());
var loc = e.target.tryPixelToLocation(point);
document.getElementById('longitude').value = loc.longitude;
document.getElementById('latitude').value = loc.latitude;
setPushpin(loc.longitude, loc.latitude);
}
}
So this is my code for getting current locations and put pushpin on it.
I don't get any error. Map isn't doing anything just stays on full world view.
On all other browsers works just fine, it zooms, get current location and put pushpin on it.
This is where I call map:
map = new Microsoft.Maps.Map(document.getElementById('placeForMap'), {credentials:"xxx",showMapTypeSelector:false, disableBirdseye: true});
GetLocation();
I tried to use Bing Ajax 7 controls, but same problem is there too, bing map in firefox is drop dead, and in other browser works fine.
There is no issue with the Bing Maps control. Firefox 26 has a couple of bugs in it which are causing the issue you are encountering.
I'm working to simulate files and directories structure ,using drag and drop,
my code is working fine in IE, Chrome but not working in Firefox ,
while i'm searching i found this fiddle .
> http://jsfiddle.net/G9mJw/20/
same problem works on IE,Chrome but not Firefox !
http://jsfiddle.net/G9mJw/140/
var dropzone = document.getElementById('dropzone');
var draggable = document.getElementById('draggable');
draggable.addEventListener('dragstart', onDragStart, false);
dropzone.ondragover = function(e){e.preventDefault(); }
dropzone.ondrop = function(e){ onDragOver(e); }
function onDragStart(event) {
event.dataTransfer.setData('text/html', null); //cannot be empty string
}
function onDragOver(event) {
var counter = document.getElementById('counter');
counter.innerHTML = parseInt(counter.innerHTML) + 1;
}
I am making a dynamic script call to load some extenal JS before window's onload event. Here is the sample code.
var temp = document.createElement('script');
temp.type = 'text/javascript';
temp.async = temp.defer= true;
temp.src = "http://stevesouders.com/efws/iframe-empty.php?t==";
window.setTimeout(function(){document.getElementsByTagName('head')[0].appendChild(temp)},0);
This code is perfectly working on IE (Window onload event is not waiting for dynamic script resource download). However it's not working on Firefox. Window onload event is waiting for the dynamic script resource download.
Are there any workarounds for this issue. You can use http://nidhisekhar.com/samples/async_script_call_settimeout.html link to see the behavior on IE and Firefox. I appreciate your help.
Thanks,
Raja
try this JavaScript function:
// Adds script tag to head of the page
function addScriptToHead(source, code, type) {
var script = document.createElement('script');
if (type === 'js') {
script.setAttribute('type', 'text/javascript');
}
if (source !== '') {
script.setAttribute('src', source);
}
if (code !== '') {
if (document.all && !window.opera) {
script.text = code;
} else {
script.innerHTML = code;
}
}
document.getElementsByTagName('head')[0].appendChild(script);
}
call example:
addScriptToHead(path, '', 'js');
PLEASE READ THE UPDATE #2 BELOW IF YOU ARE INTERESTED IN THIS PROBLEM ;)
Say I put this code into the JS of my extension.
var reader = {
onInputStreamReady : function(input) {
var sin = Cc["#mozilla.org/scriptableinputstream;1"]
.createInstance(Ci.nsIScriptableInputStream);
sin.init(input);
sin.available();
var request = '';
while (sin.available()) {
request = request + sin.read(512);
}
console.log('Received: ' + request);
input.asyncWait(reader,0,0,null);
}
}
var listener = {
onSocketAccepted: function(serverSocket, clientSocket) {
console.log("Accepted connection on "+clientSocket.host+":"+clientSocket.port);
input = clientSocket.openInputStream(0, 0, 0).QueryInterface(Ci.nsIAsyncInputStream);
output = clientSocket.openOutputStream(Ci.nsITransport.OPEN_BLOCKING, 0, 0);
input.asyncWait(reader,0,0,null);
}
}
var serverSocket = Cc["#mozilla.org/network/server-socket;1"].
createInstance(Ci.nsIServerSocket);
serverSocket.init(-1, true, 5);
console.log("Opened socket on " + serverSocket.port);
serverSocket.asyncListen(listener);
Then I run Firefox and connect to the socket via telnet
telnet localhost PORT
I send 5 messages and they get printed out, but when I try to send 6th message I get
firefox-bin: Fatal IO error 11 (Resource temporarily unavailable) on X server :0.0.
Even worse, when I try to put this same code into an XPCOM component (because that's where I actually need it), after I try sending a message via telnet I get
Segmentation fault
or sometimes
GLib-ERROR **: /build/buildd/glib2.0-2.24.1/glib/gmem.c:137: failed to allocate 32 bytes
aborting...
Aborted
printed to the terminal from which I launched firefox.
This is really weird stuff.. Can you spot something wrong with the code I've pasted or is smth wrong with my firefox/system or is the nsIServerSocket interface deprecated?
I'm testing with Firefox 3.6.6.
I would really appreciate some answer. Perhaps you could point me to a good example of using Sockets within an XPCOM component. I haven't seen many of those around.
UPDATE
I just realised that it used to work so now I think that my Console
component breaks it. I have no idea how this is related. But if I
don't use this component the sockets are working fine.
Here is the code of my Console component. I will try to figure out
what's wrong and why it interferes and I'll post my findings later.
Likely I'm doing something terribly wrong here to cause Segmentation
faults with my javascript =)
Voodoo..
components/Console.js:
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;
Console.prototype = (function() {
var win;
var initialized = false;
var ready = false;
var _log = function(m, level, location) {
if (initialized&&ready) {
var prefix = "INFO: ";
switch (level) {
case "empty":
prefix = ""
break;
case "error":
prefix = "ERORR: "
break;
case "warning":
prefix = "WARNING: "
break;
}
win.document.getElementById(location).value =
win.document.getElementById(location).value + prefix + m + "\n";
win.focus();
} else if (initialized&&!ready) {
// Now it is time to create the timer...
var timer = Components.classes["#mozilla.org/timer;1"]
.createInstance(Components.interfaces.nsITimer);
// ... and to initialize it, we want to call
event.notify() ...
// ... one time after exactly ten second.
timer.initWithCallback(
{ notify: function() { log(m); } },
10,
Components.interfaces.nsITimer.TYPE_ONE_SHOT
);
} else {
init();
log(m);
}
}
var log = function(m, level) {
_log(m, level, 'debug');
}
var poly = function(m, level) {
_log(m, "empty", 'polyml');
}
var close = function() {
win.close();
}
var setReady = function() {
ready = true;
}
var init = function() {
initialized = true;
var ww = Components.classes["#mozilla.org/embedcomp/window-
watcher;1"]
.getService(Components.interfaces.nsIWindowWatcher);
win = ww.openWindow(null, "chrome://polymlext/content/
console.xul",
"console", "chrome,centerscreen,
resizable=no", null);
win.onload = setReady;
return win;
}
return {
init: init,
log : log,
poly : poly,
}
}());
// turning Console Class into an XPCOM component
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
function Console() {
this.wrappedJSObject = this;
}
prototype2 = {
classDescription: "A special Console for PolyML extension",
classID: Components.ID("{483aecbc-42e7-456e-b5b3-2197ea7e1fb4}"),
contractID: "#ed.ac.uk/poly/console;1",
QueryInterface: XPCOMUtils.generateQI(),
}
//add the required XPCOM glue into the Poly class
for (attr in prototype2) {
Console.prototype[attr] = prototype2[attr];
}
var components = [Console];
function NSGetModule(compMgr, fileSpec) {
return XPCOMUtils.generateModule(components);
}
I'm using this component like this:
console = Cc["#ed.ac.uk/poly/console;1"].getService().wrappedJSObject;
console.log("something");
And this breaks the sockets :-S =)
UPDATE #2
Ok, if anyone is interested in checking this thing out I would really
appreciate it + I think this is likely some kind of bug (Seg fault
from javascript shouldn't happen)
I've made a minimal version of the extension that causes the problem,
you can install it from here:
http://dl.dropbox.com/u/645579/segfault.xpi
The important part is chrome/content/main.js:
http://pastebin.com/zV0e73Na
The way my friend and me can reproduce the error is by launching the
firefox, then a new window should appear saying "Opened socket on
9999". Connect using "telnet localhost 9999" and send a few messages.
After 2-6 messages you get one of the following printed out in the
terminal where firefox was launched:
1 (most common)
Segmentation fault
2 (saw multiple times)
firefox-bin: Fatal IO error 11 (Resource temporarily unavailable) on
X
server :0.0.
3 (saw a couple of times)
GLib-ERROR **: /build/buildd/glib2.0-2.24.1/glib/gmem.c:137: failed
to
allocate 32 bytes
aborting...
Aborted
4 (saw once)
firefox-bin: ../../src/xcb_io.c:249: process_responses: Assertion
`(((long) (dpy->last_request_read) - (long) (dpy->request)) <= 0)'
failed.
Aborted
If you need any more info or could point me to where to post a bug
report :-/ I'll be glad to do that.
I know this is just one of the many bugs... but perhaps you have an
idea of what should I do differently to avoid this? I would like to
use that "console" of mine in such way.
I'll try doing it with buffer/flushing/try/catch as people are suggesting, but I wonder whether try/catch will catch the Seg fault...
This is a thread problem. The callback onInputStreamReady happened to be executed in a different thread and accessing UI / DOM is only allowed from the main thread.
Solution is really simple:
change
input.asyncWait(reader,0,0,null);
to
var tm = Cc["#mozilla.org/thread-manager;1"].getService();
input.asyncWait(reader,0,0,tm.mainThread);