开发者

Geolocation without permission in manifest

开发者 https://www.devze.com 2023-03-19 14:31 出处:网络
Is it possible to use geolocation API in chrome extension without including the \"geoloc开发者_运维问答ation\" permission in manifest.json?

Is it possible to use geolocation API in chrome extension without including the "geoloc开发者_运维问答ation" permission in manifest.json?

Like can we ask permission through the background.html file which runs the extension?


You can use it in a content script without declaring a permission.

This would trigger a standard notification bar asking if you want to allow current site (not your extension) to access geolocation. If user allows it, you can then pass received geolocation position to a background page for further processing.

This approach might work if your extension is injecting a content script to a single domain, otherwise user would have to allow geolocation for each domain they visit.

The code should look like:

navigator.geolocation.getCurrentPosition(function(position) {
    console.log("Latitude : "+position.coords.latitude+":"+"Longitude : "+ position.coords.longitude);
});


Nope:

"An array of permissions that the extension or app might use. Each permission can be either one of a list of known strings (such as "geolocation") or a match pattern that gives access to one or more hosts. Permissions can help to limit damage if your extension or app is attacked."

http://code.google.com/chrome/extensions/manifest.html

...and here:

Your physical location "geolocation" permission Allows the extension to use the proposed HTML5 geolocation API without prompting the user for permission.

http://code.google.com/chrome/extensions/permission_warnings.html

Actually, after looking at it a bit more you can but the user will be prompted for permission:

http://www.html5rocks.com/en/tutorials/geolocation/trip_meter/

...and this page from Google says you can use this API and others:

http://code.google.com/chrome/extensions/api_other.html

0

精彩评论

暂无评论...
验证码 换一张
取 消