Google Drive Realtime API in a Chrome Packaged App

后端 未结 2 1495
名媛妹妹
名媛妹妹 2021-01-16 21:53

Has anyone figured out how to use the Google Drive Realtime API in a Chrome Packaged App?

Loading gapi in a sandboxed iframe results in:

Uncaugh

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-16 22:08

    I've spent a bit of time investigating how to make this possible. The best option I have come up with is to use a host page and a webview element as a container for an external site. I believe you may be able to use the webview to access resources that come packaged with the app using webview partitions though I haven't tried yet.

    Trying to load the Google Javascript Client Library in a Chrome App page throws the DOM exception you're seeing due to it's use of window.sessionStorage which is not accessible from a chrome app.

    manifest.json

    {
      "name": "Moo.do",
      "description": "Moo.do - Organize your way",
      "version": "0.1",
      "manifest_version": 2,
      "app": {
        "background": {
          "scripts": [ "chromeapp.js" ]
        }
      },
      "permissions": [
        "storage",
        "webview"
      ]
    }
    

    chromeapp.js

    chrome.app.runtime.onLaunched.addListener(function() {
      chrome.app.window.create('test.html', {
        'bounds': {
          'width': 400,
          'height': 500
        }
      });
    });
    

    test.html

    
        
        
    
    
    
    
    
    
    
    
    
    

    test.js

    function handleNewWindow(evNew)
    {
        var authView = document.createElement('webview');
        authView.id = 'authView';
        authView.classList.add('view');
    
        document.body.appendChild(authView);
    
        authView.addEventListener('exit', function (e)
        {
            debugger;
        });
    
        authView.addEventListener('loadredirect', function (e)
        {
            debugger;
        });
    
        evNew.window.attach(authView);
    }
    
    document.addEventListener('DOMContentLoaded', function ()
    {
        var mainView = document.getElementById('mainView');
    
        mainView.addEventListener('newwindow', handleNewWindow);
    });
    

提交回复
热议问题