electrongoogle-picker

Can I use the Google Picker API in an electron app?


I'm trying to use the Google Picker API to display a picker for the user to select a file. I have this working great in a web app (in a normal browser), but when I run the same code in an electron app, I see a 400 message in the popup iframe, and get the following console errors:

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://docs.google.com') does not match the recipient window's origin ('file://').
Failed to load resource: the server responded with a status of 400 ()

The core problem seems to be that the electron browser window has an origin of file://. This seems to cause two problems:

  1. The (chromium) browser security blocks the cross-origin iframe communication
  2. Google rejects the request as not coming from a valid origin (and you can't add file:// as an origin in the developer console)

I can't think of any way to overcome these problems, but I'm hoping that someone has an idea.


Solution

  • You could create an app and host it in something like following, and then point the electron BrowserWindow to the url.

    https://app.yourdomain.name/gdrive/picker?token=access_token
    

    That should work I believe.