Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to execute 'fetch' on 'Window': member signal is not of type AbortSignal. #3005

Closed
cameroncruz opened this issue Jun 27, 2020 · 4 comments
Assignees

Comments

@cameroncruz
Copy link

cameroncruz commented Jun 27, 2020

Hi, I'm running into issues integrating basic authentication using Realm with Electron. I believe this issue is related to Azure/azure-sdk-for-js#5143. I noticed that in realm-js, lib/NetworkTransport.js line 46 is where global fetch is being retrieved. While avoiding global fetch is the solution azure-sdk-for-js decided to pursue, is there a short-term solution I can apply to get unblocked? Thanks.

Goals

I want to enable email/password Login based on https://docs.mongodb.com/realm/tutorial/react-native/ for my Electron app.

Expected Results

Calling app.logIn(creds) on a Realm.App to return a valid user.

Actual Results

I receive the following error:
Failed to execute 'fetch' on 'Window': member signal is not of type AbortSignal.

Steps to Reproduce

Following this tutorial https://docs.mongodb.com/realm/tutorial/react-native/ with Electron.

Code Sample

app = new Realm.App(appConfig);
const creds = Realm.Credentials.emailPassword(email, password);
const newUser = await app.logIn(creds);

Version of Realm and Tooling

  • Realm JS SDK Version: realm@v10.0.0-beta.6
  • Node or React Native: Node
  • Client OS & Version: MacOS 10.15.5
  • Which debugger for React Native: None
@cameroncruz
Copy link
Author

cameroncruz commented Jun 27, 2020

I built realm@v10.0.0-beta.6 from source with the following change to NetworkTransport.js lines 43-47:

if (!DefaultNetworkTransport.fetch) {
    // Try to get it from the global
    if (false) {
        DefaultNetworkTransport.fetch = fetch.bind(window);
    }

which seems to do the trick. Is there any motivation to continue trying to get global fetch?

@kraenhansen
Copy link
Member

Are you running this code from the main or a renderer process?
If you are available, it would be great to get a repository with a minimal app reproducing this error.

@kraenhansen
Copy link
Member

Okay - I managed to reproduce the error in the renderer process, using the following project structure:

package.json

{
  "name": "realm-js-electron-test",
  "version": "0.1.0",
  "private": true,
  "main": "index.js",
  "scripts": {
    "test": "electron index.js"
  },
  "devDependencies": {
    "electron": "^8.1.1"
  },
  "dependencies": {
    "realm": "^10.0.0-beta.7"
  }
}

.npmrc

target=8.1.1
runtime=electron
disturl=https://atom.io/download/electron

index.js

const { app, BrowserWindow } = require("electron");
const Realm = require("realm");

/*
async function useRealm() {
    const app = new Realm.App("realmwebtestapp-ybnna");
    const credentials = Realm.Credentials.anonymous();
    const user = await app.logIn(credentials);
    console.log(user);
}

app.on("ready", () => {
    console.log("App is ready - lets use Realm");
    useRealm().then(() => {
        console.log("All done ...");
    }, err => {
        console.error(err);
        process.exit(1);
    });
});
*/

app.on("ready", () => {
    const window = new BrowserWindow({ webPreferences: {  nodeIntegration: true } });
    window.loadFile("index.html");
});

index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Testing Realm JS</title>
    <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
  </head>
  <body>
    <h1>Testing Realm JS</h1>
    <script>
        const Realm = require("realm");
        
        async function useRealm() {
            const app = new Realm.App("realmwebtestapp-ybnna");
            const credentials = Realm.Credentials.anonymous();
            const user = await app.logIn(credentials);
            console.log(user);
        }
        
        useRealm().then(() => {
            console.log("All done ...");
        }, err => {
            console.error(err);
            process.exit(1);
        });
    </script>
  </body>
</html>

@kraenhansen
Copy link
Member

The PR has been merged, you can expect a fix for this in the upcoming v10 beta release.

@RealmBot RealmBot closed this as completed Jul 1, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants