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

🐛 BUG: The 'credentials' field on 'RequestInitializerDict' is not implemented. #2514

Closed
Kaperstone opened this issue Jan 8, 2023 · 17 comments
Labels
bug Something that isn't working

Comments

@Kaperstone
Copy link

Kaperstone commented Jan 8, 2023

Which Cloudflare product(s) does this pertain to?

Workers/Other

What version of Wrangler are you using?

2.6.2

What operating system are you using?

Windows

Describe the Bug

I am testing locally
EDIT: To emphasize, when I press L to test locally, it is working fine but when I deploy to Cloudflare or turn local mode off, it is showing the error.

Whenever I include credentials in the header of a fetch request, I am receiving this error.
This has became an issue since I ably-js has stopped working entirely throwing this error.

I use hono.js to simplify the usage of workers so basically a reproduction would be

import {Hono} from "hono"

app.get("/", ctx => {
  new fetch("https://example.com/api/", {
  headers,
  method: "POST",
  body: "",
  credentials: headers.has("authorization") ? "include" : "same-origin"
})
@Kaperstone Kaperstone added the bug Something that isn't working label Jan 8, 2023
@KianNH
Copy link
Contributor

KianNH commented Jan 8, 2023

FYI, this is a bug in local development - Cloudflare Workers do not support the credentials property in options.

@Kaperstone
Copy link
Author

Kaperstone commented Jan 8, 2023

As I stated, this is a bug in deployment.

Here is a log from a deployed code, workers > logs

{
  "outcome": "ok",
  "scriptName": "wrangler",
  "exceptions": [],
  "logs": [
    {
      "message": [
        "  <-- POST /rest/v1/friends_messages"
      ],
      "level": "log",
      "timestamp": 1673176328277
    },
    {
      "message": [
        "ably error:The 'credentials' field on 'RequestInitializerDict' is not implemented."
      ],
      "level": "log",
      "timestamp": 1673176328331
    },
    {
      "message": [
        "ably error:The 'credentials' field on 'RequestInitializerDict' is not implemented."
      ],
      "level": "log",
      "timestamp": 1673176328331
    },
    {
      "message": [
        "  --> POST /rest/v1/friends_messages \u001b[32m200\u001b[0m 54ms"
      ],
      "level": "log",
      "timestamp": 1673176328331
    }
  ],
}

And the opposite, it is an error only in deployment

as I stated, local mode is working fine, only when local-mode is off and/or after deployment to Cloudflare.

EDIT: Last but not least, I can't do anything with the situation.
Ably is using this header, Cloudflare does not support.

Then it means I cannot use Cloudflare Workers.

@KianNH
Copy link
Contributor

KianNH commented Jan 8, 2023

As I said, this is a bug in local development.

It is not supported in Workers - the bug is that local development does support it when it shouldn't.

You would need to stop the package from using fields that aren't implemented in Cloudflare Workers.

https://github.com/cloudflare/workerd/blob/902b65ace3c5c0f5ae4b432fae976f28ddaec1ec/src/workerd/api/http.h#L510-L517

@Kaperstone
Copy link
Author

Oh, so the bug is that the local does support it when it shouldn't.

Got you, so my only options are to give up on Workers or Ably.

@randomairborne
Copy link

is it possible to not make this a hard crash? Given workers are not in a browser, the credentials policy shouldn't affect them... so is there some harm to making this not hardcrash any third-party library that also wants to support a browser?

@lachlancollins
Copy link

@KianNH I've just run into this problem in a SvelteKit app using the @sveltejs/adapter-cloudflare. I'm just wondering why the credentials field isn't supported? Are there any plans to support the full fetch request API? Other edge runtimes like Deno seem to have all properties.

@randomairborne
Copy link

Well, credentials doesn't do anything here- it only exists to turn off browser settings, it is ignored in server-side applications (as i understand). The issue (i think) is that cloudflare throws rather then silently ignoring them, see cloudflare/workerd#902 for a related issue i created

@lachlancollins
Copy link

Well, credentials doesn't do anything here- it only exists to turn off browser settings, it is ignored in server-side applications (as i understand). The issue (i think) is that cloudflare throws rather then silently ignoring them, see cloudflare/workerd#902 for a related issue i created

Credentials are definitely not useless in a server environment - for example, it's a core part of SvelteKit's fetch. I've also migrated my app from Cloudflare Workers to Deno Deploy and it works as expected.

I understand the focus of this issue has shifted towards throwing a warning in development, I'm just curious about why it hasn't been added. For example, I checked the WinterCG and couldn't find anything on fetch, so maybe there isn't a common standard yet.

@randomairborne
Copy link

Aren't credentials only used to bypass the fact that the browser prevents you from sending custom cookies? Nothing prevents you from doing this, and I don't see what deno actually does with the information you give it.

@lachlancollins
Copy link

lachlancollins commented Jul 22, 2023

Aren't credentials only used to bypass the fact that the browser prevents you from sending custom cookies? Nothing prevents you from doing this, and I don't see what deno actually does with the information you give it.

True, I think SvelteKit processes the cookies for you, based on the credentials field. So I guess I just need a runtime that silently ignores the credentials option and fetches regardless!

@martinsotirov
Copy link

This makes it impossible to use the @directus/sdk

@snilan
Copy link

snilan commented Nov 25, 2023

Running into this issue trying to use the @huggingface/inference package

@multipliedtwice
Copy link

Am I correctly understanding, the set-cookie header sent by a server won't work on Cloudflare?

@riderx
Copy link

riderx commented Feb 22, 2024

fucked my prod with this bug, all test passed in local ^^

@ImLunaHey
Copy link

Similar issue here cloudflare/workerd#698

@Thimows
Copy link

Thimows commented Mar 23, 2024

Same issue:

The 'credentials' field on 'RequestInitializerDict' is not implemented

This makes it IMPOSSIBLE to run agents that use the Webbrowser tool from Langchain (langchain/tools/webbrowser)...

@moritzmla
Copy link

Same issue:

The 'credentials' field on 'RequestInitializerDict' is not implemented

Is there any workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that isn't working
Projects
Archived in project
Development

No branches or pull requests