Code working fine in firefox not in Chrome - google-chrome

I have gone through couple of same questions also, but no one can give me understanding that what is happening in my code. My code is:
if (navigator.geolocation) {
console.log(" in navigator If");
navigator.geolocation.getCurrentPosition(showPosition, null, {
enableHighAccuracy : true,
maximumAge : 1000,
timeout : 0
});
} else {
console.log("in Navigator else");
alert("Browser doesn't support location detection. Please pass latitude & longitude for current location in URL. Thanks.");
}
this code working fine in firefox but not in chrome
I am using Mac, Jboss .
In Chrome control doesn't go in any of condition (neither if , nor else )

navigator.geolocation doesn't work if you are directly running from the filesystem on chrome. Make sure the file is hosted on some local web server.

Related

Chrome devtools lighthouse not working, serviceworker

I got Chrome auto updated and now I have the lighthouse tab in devtools instead of the audit.
I used to be able to test my own page via audit and get full score: https://medda86.com/
But now the devtools lighthouse crashes and I think it's because of my serviceworker or something.
It used to run fine before Chrome update, not sure what else it could be.
Please have a go at it if you want and try to find out what it is,
I can't pinpoint exactly what it is.
The service worker should be working, just install, cache, delete old cache, and fetch latest data.
But could be something that have changed.
Chrome version:
Chrome is up to date
Version 95.0.4638.54 (Official Build) (64-bit)
Here is my service worker:
var cacheName = 'site-cache-v1';
// Install
self.addEventListener('install', function(event) {
event.waitUntil(
caches.open(cacheName).then(function(cache) {
//console.log('Service Worker Installed');
})
);
});
// Delete old cache objects
self.addEventListener('activate', function(event) {
event.waitUntil(caches.keys().then(function (keyList) {
Promise.all(keyList.map(function (key) {
if (key === cacheName) {
return;
}
caches.delete(key);
//console.log('Old Service Worker '+key+' Deleted');
}));
}));
//console.log('Service Worker Activated');
});
self.addEventListener('fetch', function(event) {
//console.log('Fetch', event.request);
});
I found the issue, it's google. https://github.com/GoogleChrome/lighthouse/issues/13236
It's the chrome version that makes the lighthouse tab not working. This chrome version has some other issues as well.

Meteor camera - permission denied on Chrome

I have created a small app on MeteorJS, which is using the camera at some point to take pictures.
To do so, I just use the mdg:camera package.
It all works fine on my localhost:3000
Now the problem came when I deployed the app to meteor (xxx.meteor.com)
When testing it, when I try to launch the camera, Chrome complains with
Camera permission denied
Without asking me first if I want to allow or block the camera.
They suggest going to :
Go to Settings > "Show advanced settings..." > "Content settings..." > Media heading > "Manage exceptions...", then find this website in the list and allow video capture.
After going there, I can see my localhost:3000 being allowed, but that's it. I can't find any options to add manually any new exceptions.
Would any of you had this issue ? Is it a Meteor issue, where the settings are not set properly, or a Chrome settings issue ?
PS : if that helps, here is how I use the camera (I take the picture and save it in session):
var options = {
width: 350,
height: 350,
quality: 75,
};
MeteorCamera.getPicture(options, function(err, data) {
if (err) {
console.log('error', err);
}
if (data) {
img = Session.get('img');
if( typeof img == 'undefined') {
img = [];
}
img.push( {hash: (Date.now() / 1000 | 0), data: data});
Session.set('img', img);
}
});
Update
I have tried on Opera, camera works fine. It first complains that the permission is not right, but it gives me at the same time a popup to allow or block the camera. After clicking on Allow, the camera works fine.
On Chrome even with removing the cookies (maybe the preference would be saved in one ??), still no luck.

geoLocation.GetCurrentPosition always fails in IE 11

The script below works fine in FireFox and Chrome, but in Internet Explorer 11, it always fails (with POSITION_UNAVAILABLE).
I have set the browser to allow requests for position, and I agree to the prompt the browser presents me when requesting permission.
I'm almost certain that this worked fine a few months ago when I was last experimenting with it. What could I be missing as far as IE's settings?
<script type="text/javascript">
$(document).ready(function () {
if (Modernizr.geolocation)
{
navigator.geolocation.getCurrentPosition(positionSuccess, positionError, { enableHighAccuracy: true, maximumAge: 60000, timeout: 10000 })
}
else
{
$("#GeoError").html("Unable to retrieve current position.")
}
});
function positionSuccess(position)
{
$("#Latitude").val(position.coords.latitude);
$("#Longitude").val(position.coords.longitude);
}
function positionError(error)
{
var message = "";
// Check for known errors
switch (error.code) {
case error.PERMISSION_DENIED:
message = "This website does not have your permission to use the Geolocation API";
break;
case error.POSITION_UNAVAILABLE:
message = "Your current position could not be determined.";
break;
case error.PERMISSION_DENIED_TIMEOUT:
message = "Your current position could not be determined within the specified timeout period.";
break;
}
// If it's an unknown error, build a message that includes
// information that helps identify the situation, so that
// the error handler can be updated.
if (message == "") {
var strErrorCode = error.code.toString();
message = "Your position could not be determined due to " +
"an unknown error (Code: " + strErrorCode + ").";
}
$("#GeoError").html(message)
}
</script>
Also, I get the same failure in IE11 when I try http://html5demos.com/geo, where both FireFox and Chrome work fine.
Does you enable the Location Service?
I have had the same issue, it worked after I enabled the Location Service in my windows 2016.
This page shows how to enable the Location Service in windows 10.
I have had the same issue in IE11 only.
I had to set enableHighAccuracy to false to get it to work. Once I did that IE worked as expected.
In Internet Options, click on the Privacy tab. Uncheck the Never allow websites to request your physical location box, hit on OK.
After making these changes, the http://html5demos.com/geo now worked for me. Initially it didn't.
aha, just discovered something.
Chrome apparently uses the WIFI access points to help finding the location.
IE11 (and edge) just falls back to the default location in your windows settings, if there is no immediate GPS signal.

Chrome extension: (DOM)Debugger API does not work anymore

Our chrome extension does not work correctly anymore since version 37.0.2062.103 (It used to work correctly on chrome version 36.0.1985.143).
Specifically, the debugger API has stopped working for us when we use the DOMDebugger.
See the attached code: (background.js)
chrome.tabs.onUpdated.addListener(function(tabId,changeInfo,tab){
if( changeInfo.status == "loading" && tab.active){
var debugId = {tabId:tabId};
chrome.debugger.attach(debugId, '1.0', function() {
chrome.debugger.sendCommand(debugId, 'Debugger.enable', {}, function() {
chrome.debugger.sendCommand(debugId, "DOMDebugger.setEventListenerBreakpoint", {'eventName':'click'},
function(result) {
console.log('registering click');
});
});
});
}
});
chrome.debugger.onEvent.addListener(onEvent);
function onEvent(debuggeeId, method,params) {
if(method=="Debugger.paused"){
console.log('DONE!');
}
};
The extension successfully starts the debugger. we get the yellow debugger ribbon.
We also see the 'registering click' msg in the console. the result argument is an empty object {} (line 8).
However upon clicking on a button that has a click event listener nothing happens.
It used to work without any issues.
It seems like it regressed with https://codereview.chromium.org/305753005. One needs to call "DOM.enable" for it to work now. On the Chrome side, we should implicitly enable DOM domain upon setEventListenerBreakpoint for backwards compatibility. Unfortunately it already squeezed into the stable release.

How to get the root folder in Chrome Extensions?

I am developing a Chrome Extesion for the first time and I am following the only guide that explains something about that: HTML5 ROCKS - FILESYSTEM.
I need to get storage for my extension and I resolved so:
window.webkitStorageInfo.requestQuota(window.PERSISTENT,1024*1024, onInitFs, errorHandler);
Ok, it works.
Now I need to create a xml file into the root, but in "onInitFs" the "fs" var is only a number and "fs.root" can't get it.
function onInitFs(fs){
console.log(fs.root); // -> Undefined
fs.root.getFile('list.xml', {create: true, exclusive: true}, function(fileEntry) {
fileEntry.isFile === true;
fileEntry.name == 'list.xml';
fileEntry.fullPath == '/list.xml';
}, errorHandler);
}
Can anybody explain why it doesn't work and how to resolve this issue?
Using RequestFileSystem within Chrome Extension
In order to use the FileSystem API as a root filesystem for your Chrome extension, you can actually use window.webkitRequestFileSystem instead of requestQuota.
window.webkitRequestFileSystem(window.PERSISTENT, 1024 * 1024, function (filesystem) {
console.log(filesystem);
console.log(filesystem.root);
}, function (e) { console.log("Could not request File System"); });
This does print correctly on Chrome 15,16 and 17 for me:
DOMFileSystem
DirectoryEntry
Using requestQuota for HTML5 apps
Just for reference, this would be the way to actually request the quota (i.e., when not using a Chrome Extension). You have to request the quota (the user sees a little banner at the top of his/her window) first. The RequestFileSystem is called if the user accepts.
window.webkitStorageInfo.requestQuota(PERSISTENT, 1024*1024, function(grantedBytes) {
window.webkitRequestFileSystem(PERSISTENT, grantedBytes, onInitFs, errorHandler);
}, function(e) {
console.log('Error requesting filesystem', e);
});
Eventually it might be necessary to request quota within an extension. Currently this can be circumvented with the unlimitedStorage permission. For the current state of implementation/storage types, see http://code.google.com/chrome/whitepapers/storage.html
Until current stable version 17.x, you cannot use HTML5 FileSystem API in Chrome extension. I have try this, the browser will crash down if I call FileSystem API in background page.
And here is a HTML5 API list what you can use in Chrome extension:
http://code.google.com/chrome/extensions/api_other.html