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

Proposal: add origin global #24125

Open
oles opened this issue Jun 6, 2024 · 3 comments
Open

Proposal: add origin global #24125

oles opened this issue Jun 6, 2024 · 3 comments
Labels
runtime Relates to code in the runtime crate suggestion suggestions for new features (yet to be agreed) web related to Web APIs

Comments

@oles
Copy link

oles commented Jun 6, 2024

It seems there's a miss match between the implementation of origin and/or globalThis.origin and lib.dom.d.ts

$ deno eval "console.log(origin)"
error: Uncaught (in promise) ReferenceError: origin is not defined
console.log(origin)

Screenshot from 2024-06-06 23-16-09

Screenshot from 2024-06-06 23-16-36

location works as expected when a --location is and isn't specified

$ deno eval --location=http://localhost:3000 "console.log(location)"
Location {
  hash: "",
  host: "localhost:3000",
  hostname: "localhost",
  href: "http://localhost:3000/",
  origin: "http://localhost:3000",
  pathname: "/",
  port: "3000",
  protocol: "http:",
  search: ""
}
$ deno eval "console.log(location)"
undefined

But it doesn't fix the issue with origin if you do

$ deno eval --location=http://localhost:3000 "console.log(origin)"
error: Uncaught (in promise) ReferenceError: origin is not defined
console.log(origin)

$ deno --version
deno 1.44.1 (release, x86_64-unknown-linux-gnu)
v8 12.6.228.3
typescript 5.4.5
@bartlomieju
Copy link
Member

That's correct, origin is not an available global. Not everything that is defined in lib.dom.d.ts is available in Deno - eg. document is not available either. What use case do you have for origin?

@oles
Copy link
Author

oles commented Jun 6, 2024

I see, thanks for the clarification!

I had an issue where, after a refactor, an origin variable got lost, and I didn't notice until I ran my test.
I didn't know that origin was a global, and I didn't expect it to cause Deno to throw an error.


Side-note:

Having an easy way to get the origin is handy though, and using globalThis.location.origin/location.origin to get it is fine when globalThis.origin/origin isn't possible/supported yet.

I'd ideally like to configure the --location from a .env file though 🤔

@lucacasonato lucacasonato changed the title ReferenceError: origin is not defined Proposal: add origin global Jun 7, 2024
@lucacasonato lucacasonato added suggestion suggestions for new features (yet to be agreed) web related to Web APIs runtime Relates to code in the runtime crate labels Jun 7, 2024
@oles
Copy link
Author

oles commented Jun 9, 2024

For anyone else experiencing a similar issue - I found the no-undef deno_lint rule to be very useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
runtime Relates to code in the runtime crate suggestion suggestions for new features (yet to be agreed) web related to Web APIs
Projects
None yet
Development

No branches or pull requests

3 participants