Skip to content

fetch fails in javascript kernel when requesting to CORS'ed API #3744

Open
@estalldecker

Description

@estalldecker

Describe the bug

I'm not sure if it's a bug or is it by design but here is the issue I have.

Executing a javascript fetch in a javascript kernel works this way:

test = await fetch('https://jsonplaceholder.typicode.com/todos/1');
response = await test.json();
console.log(response);

but when I want to do a fetch to an auth'ed API, I guess it's captured by the underlying electron instance validating CORS?, because the fetch fails and it doesn't even appear in Fiddler:

testAPIcall = await fetch('<some api with auth and CORS>', {
  headers: {
    "Content-Type": "application/json",
    Authorization: `Bearer ${accessToken}`
  } 
});

The error is this:

Image

the same api calls works ok with other kernels: c#, python, http.
Could it be possible to use a different fetch call that doesn't validate CORS for the js kernel?

Please complete the following:

Which version of .NET Interactive are you using? (In a notebook, run the #!about magic command. ):
Version: 1.0.553001+f0ec3826954ea1ab829b435418328e4aa8db58e2
Library version: 1.0.0-beta.24530.1+f0ec3826954ea1ab829b435418328e4aa8db58e2
Build date: 2024-11-01T00:19:19.2878193Z

  • OS
    • Windows 11
    • Windows 10
    • macOS
    • Linux (Please specify distro)
    • iOS
    • Android
  • Browser
    • Chrome
    • Edge
    • Firefox
    • Safari
  • Frontend
    • Jupyter Notebook
    • Jupyter Lab
    • nteract
    • Visual Studio Code
    • Visual Studio Code Insiders
    • Visual Studio
    • Other (please specify)

Screenshots

If applicable, add screenshots to help explain your problem.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions