googleapis / googleapis/google-api-nodejs-client

This client needs proper integration with Electron really badly

Open
#2,714 0 comments 1 reaction 0 assignees View on GitHub
type: feature request web
Dominant language
TypeScript
Stars
12.2k
Forks
2k
Avg merge
1d 9h
Merged PRs (30d)
24

Description

First of all, This client is a massive time saver for the developers and really grateful for the time and energy you all have put into this. Second of all, I'm not even close to an expert on any of these things. I just recently started using this client. I've already been through previously tracked issues (#1878, #1083, #2085) that's related to my issues. I'm opening this new feature request since @JustinBeckwith advised me to do so and I'd like to share my suggestions.

**Is your feature request related to a problem? Please describe.**
Currently there's no way to practically use this client for uploading tasks in Electron renderer and from what I'm seeing, it's for no good reason. As you all may know, Electron's renderer process is fully capable of using Node.js APIs, so the client shouldn't behave in a different way in that context. I'm fully behind the idea of added support for the browser but in my opinion it should be a choice for the developer and shouldn't cost existing good functionality. I've seen the suggestion of IPC everywhere but any Electron dev with the slightest experience knows that's hardly a solution. I personally have succeeded in avoiding usage of IPC almost 99% of the time even in fairly massive applications.

When you boil this issue down to a gist, all this trouble just because how [`isBrowser()`](https://github.com/googleapis/nodejs-googleapis-common/blob/master/src/isbrowser.ts) is implemented.

**Describe the solution you'd like**
The client should respect the `fetchImplementation` property set in `gaxios` options.

```js
const nodeFetch = require('node-fetch/lib/index').default;

drive.files.create({
requestBody: {...fileMetadata},
media: media,
fields: 'id'
}, {
fetchImplementation: nodeFetch, // `isBrowser()` function should respect this option
/* Or something like this */
environment: 'node' // or 'browser'
})
```

**Describe alternatives you've considered**
I've manually overridden [`isBrowser()`](https://github.com/googleapis/nodejs-googleapis-common/blob/98edc86818868aaedd291268b79347298d84b95f/src/isbrowser.ts#L14) like this:

```js
function isBrowser() {
if (process && process.type) return false;
return typeof window !== 'undefined';
}
```
And voila. Everything works perfectly as intended.

At the end, now I'm using my own forks of `googleapis-common` and `@googleapis/drive` in my projects because from what I'm seeing, there's no other option.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.