Manifest v3 background page: using google api client on the background page

513 views
Skip to first unread message

Dzianis Sheka

unread,
Feb 18, 2019, 4:36:54 AM2/18/19
to Chromium Extensions
I'm a developer on timyo.com and implement the Gmail chrome extension for our service.

Right now we are using Google API client for javascript. The gapi client itself is the loader script which loads the text of the last version of the gapi client and executes it using eval in the context of the page.  We are loading that client in background script and making requests to Google services (Gmail API mostly).

With new manifest the scenario, it will not be possible anymore - it is no dom in ServiceWorke and the Google API client will not work.


There are also 2 standard libs to interact with Gmail:

* open sourced gmailjs https://github.com/KartikTalwar/gmail.js
It injects itself into the Gmail page and all legacy iframe and proxying requests to google private API to make triggers to extensions.
Seems that lib will be broken because it will be forbidden to inject the script into the host page.

* the second lib - closed source https://www.inboxsdk.com/ from StreakCRM. It injects script to host page too and interact with the page almost in the same way as gmailjs. The main issue here - that the lib violates no remote host code. 

So generally what we will have in v3
1) no cors requests from content scripts
2) no proxying because it will be impossible to inject the script to host page
3) no Google API client because of it usage of dom 

So all mass google extensions based on gmailjs / inboxsdk / Google API client will be impossible to implement with chrome extensions.

Joshua Weaver

unread,
Mar 25, 2019, 3:35:43 PM3/25/19
to Chromium Extensions
Is this acurate? Where is the documentation on V3 you're referencing that makes you believe inboxSDK will no longer work?

I'm looking into using it also, and this is the first I've heard anything like that... so I'd love to know if that is in fact the case!

Thanks,
Joshua

Joshua Weaver

unread,
Mar 25, 2019, 3:39:50 PM3/25/19
to Chromium Extensions

Andrew

unread,
Mar 25, 2019, 4:57:59 PM3/25/19
to Chromium Extensions
Yes it's very confusing:
[quote]
Beginning in Manifest V3, we will disallow extensions from using remotely-hosted code.  This will require that all code executed by the extension be present in the extension’s package uploaded to the webstore.  Server communication (potentially changing extension behavior) will still be allowed.
{/quote]
So what is "Server communication" by definition if you're communicating with your server you must be accessing "remotely-hosted code". We really could do with some clarification/examples on this subject......

PhistucK

unread,
Mar 25, 2019, 6:00:37 PM3/25/19
to Andrew, Chromium Extensions
Data coming from the server, but not code.
Data can affect behavior, but in a much less arbitrary and probably safer way than code.

PhistucK


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at https://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/2eb1f3cf-93f0-4bb6-89fd-9337c15b3c96%40chromium.org.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.

thdoan

unread,
Jan 8, 2021, 2:16:20 PM1/8/21
to Chromium Extensions, PhistucK, Chromium Extensions, Andrew
Hey guys, I've submitted a ticket for the Chromium team to take notice of this concerning implication. Please go here and make some noise :) --> https://bugs.chromium.org/p/chromium/issues/detail?id=1164452

Jackie Han

unread,
Jan 9, 2021, 11:05:09 AM1/9/21
to thdoan, Chromium Extensions, PhistucK, Andrew
Hi thdoan,

Most Google APIs support REST interface, so you can still use Google APIs in MV3. For example:

    let url = `https://www.googleapis.com/calendar/v3/calendars/${calendarId}/events`;
    let params = new URLSearchParams();
    params.append('orderBy', 'startTime');
    // .... some other parameters
    url = url + '?' + params.toString();

    let init = {
      method: 'GET',
      headers: {
        'Authorization': 'Bearer ' + your_oauth_token,
        'Accept': 'application/json'
      },
      cache: 'no-cache'
    };

    let response = await fetch(url, init);

Personally, I don’t use gapi JavaScript client.



--
韩国恺(Jackie)

thdoan

unread,
Jan 12, 2021, 6:24:13 PM1/12/21
to Chromium Extensions, Jackie Han, Chromium Extensions
Hi Jackie,

Thanks for the code sample, I will have to play around with this approach ^^. Are there alternative libraries you can recommend that allows us to interact with Google services like Gmail and Drive?

Tom

Simeon Vincent

unread,
Jan 13, 2021, 12:41:58 AM1/13/21
to Chromium Extensions, thdoan, Jackie Han, Chromium Extensions
FYI, I just opened issue 713 on the GAPI project to discuss compatibility with MV3.

Cheers,

Simeon - @dotproto
Chrome Extensions DevRel

Jackie Han

unread,
Jan 13, 2021, 8:50:49 AM1/13/21
to thdoan, Chromium Extensions, Simeon Vincent
Hi thdoan

For gapi client, as far as I know, it uses Google API Discovery Service(similar to interface definition description) to generate client code dynamically. This is a smart solution for all google apis. But it is not always the best choice for all problems. Thank Simeon for reporting an issue to them, but I see a reply from a googler "Hi, no, it's not possible for third-party developers to bundle GAPI with
their applications.".

Now, let's forget gapi client, and talk about REST. REST api is called by HTTP, It's just data transfer, no remote or dynamic code. For example, Gmail provides dozens of apis, if you only need to use 5 of them, you only need to write a few lines of code without relying on any third-party libraries and your code size is kept very small.

Are there alternative libraries you can recommend that allows us to interact with Google services like Gmail and Drive?
 
I have used Gmail, Drive API and some other Google APIs. I suggest you read below 3 documents, that's enough.
  1. MDN Fetch API
  2. Google Drive API Reference
  3. Gmail API Reference
Above links are very stable technologies or interfaces. After writing your code, you rarely need to maintain them.
For authentication, you just need to add a "Authorization" http header with your token.
--
韩国恺(Jackie)
Reply all
Reply to author
Forward
0 new messages