Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Some features that usually require permissions in a normal web page are also available in a webview. However, instead of the normal popup "the website xyz.com wants to know your physical location - allow / deny", the app that contains the webview needs to explicitly authorize it. Here is how it works:</p> <ul> <li><p>No need to change the web page inside the webview;</p></li> <li><p>In the app, you listen for <code>permissionrequest</code> events on the <code>&lt;webview&gt;</code> element:</p></li> </ul> <pre class="lang-js prettyprint-override"><code>webview.addEventListener('permissionrequest', function(e) { if ( e.permission === 'geolocation' ) { e.request.allow(); } else { console.log('Denied permission '+e.permission+' requested by webview'); e.request.deny(); } }); </code></pre> <p>One thing to note is that the request doesn't need to be handled immediately. You can do whatever you need to do before allowing or denying, as long as you call <code>preventDefault</code> in the permissionrequest event and keep the event object from being garbage collected. This is useful if you need to do any async operation, like going to a storage to check if the URL requesting a permission should be allowed or not.</p> <p>For example:</p> <pre class="lang-js prettyprint-override"><code>webview.addEventListener('permissionrequest', function(e) { if ( e.permission === 'geolocation' ) { // Calling e.preventDefault() is necessary to delay the response. // If the default is not prevented then the default action is to // deny the permission request. e.preventDefault(); setTimeout(function() { decidePermission(e); }, 0); } }); var decidePermission = function(e) { if (e.url == 'http://www.google.com') { e.request.allow(); } // Calling e.request.deny() explicitly is not absolutely necessary because // the request object is managed by the Javascript garbage collector. // Once collected, the request will automatically be denied. // If you wish to deny immediately call e.request.deny(); } </code></pre> <ul> <li>Also note that your app needs to also request the respective permission:</li> </ul> <pre class="lang-json prettyprint-override"><code>"permissions": ["geolocation"], </code></pre> <p>The <a href="https://github.com/GoogleChrome/chrome-app-samples/blob/master/webview/index.js#L61-L72" rel="nofollow">webview sample</a> has more code for other permissions, like pointerLock and media capture.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload