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

'cocos-ignore' is not valid enum #192

Open
Bl4ckburn opened this issue Apr 16, 2024 · 3 comments
Open

'cocos-ignore' is not valid enum #192

Bl4ckburn opened this issue Apr 16, 2024 · 3 comments

Comments

@Bl4ckburn
Copy link

Hey everyone,
I am currently using nakama-js in combination with ionic (capacitor) and after upgrading the version of capacitor-android to 5.4.0 (minimum) and compile project to APK it shows an error in app from nakama (even though I don't use the cocos engine):

TYPEERROR: FAILED TO CONSTRUCT 'REQUEST': FAILED TO READ THE 'CREDENTIALS' PROPERTY FROM 'REQUESTINIT': THE PROVIDED VALUE 'COCOS-IGNORE' IS NOT A VALID ENUM VALUE OF TYPE REQUESTCREDENTIALS.

It looks as if newer versions of lib.dom block the ability to change 'credentials'. My proposal is to simply checking whether the 'credentials' property is readonly, just to start with.
I don't know how the cocos engine itself reacts to the change.

checking function:

function isWritable<T extends Object>(obj: T, key: keyof T) {
  const desc = Object.getOwnPropertyDescriptor(obj, key) || {}
  return Boolean(desc.writable)
}

and change condition line before credentials assign in buildFetchOptions function from: if (!descriptor?.set) { to if (!descriptor?.set && isWritable(fetchOptions, 'credentials')) {

I would be grateful if someone had a better idea on how to solve this problem, without cutting off the cocos engine in the future by above condition.

@lugehorsam
Copy link
Contributor

Hey @Bl4ckburn it appears that in the Ionic runtime, the credentials property is not writable, whereas in cocos, it actually just lacks a setter. So if you want to submit a PR with your change where we keep the existing logic but change cocos-ignore to just ignore (to make it more generic) and to also skip assignment if the credentials property is not writable, and test that on Ionic that'd definitely be appreciated.

@Bl4ckburn
Copy link
Author

Bl4ckburn commented Apr 17, 2024

Can you tell me how options params object looks like in cocos engine after executing buildFetchOptions function?

After deeper analysis it comes out that in WEB and Mobile APP options is always an empty object (in my case), so my isWritable function always return false. Thats why it's working.
I am afraid that this condition may completely block the cocos engine from replacing credentials.

Just in case you're wondering what values ​​"credentials" can take.

type RequestCredentials = "include" | "omit" | "same-origin";

That is code from lib.dom.d.ts in typescript lib.

@lugehorsam
Copy link
Contributor

Hey @Bl4ckburn unfortunately this is not something I can prioritize at the moment, but you are welcome to investigate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants