import.meta.url showing an extension path not the script path
See original GitHub issueI’ve reproduced on the latest version of NW.js and I’ve searched for import.meta.url
to no results.
I am not sure if this is technically possible with how NW.js works, but currently import.meta.url
prints a path into a web extension as opposed to a file system path of the script. If this is possible to be somehow intercepted and converted to the file system path, that would be very useful as it would provide an ESM-canonical way of figuring out the current script’s path on the file system. Thank you
NWJS Version : nwjs-sdk-v0.54.1-osx-x64 Operating System : macOS
Expected behavior
import.meta.url
should return a file:///
path.
Actual behavior
import.meta.url
returns chrome-extension://dicgdfmjdcflpdchdnbjfppblikeeofl/index.js
.
How to reproduce
- Download the latest SDK
- Copy it to a new folder
- Create
index.html
referencingindex.js
andpackage.json
withindex.html
formain
- Add this to
index.js
:window.addEventListener('load', () => { document.body.append(import.meta.url); });
- Run
nwjs-sdk-v0.54.1-osx-x64/nwjs.app/Contents/MacOS/nwjs .
- See the incorrect path printed:
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
Top Results From Across the Web
How should we handle import.meta #6719 - GitHub
As a developer, I would expect the import.meta.url to contain a path ending with the filename (e. g. the name of the file...
Read more >import.meta - JavaScript - MDN Web Docs
The import.meta meta-property exposes context-specific metadata to a JavaScript module. It contains information about the module, ...
Read more >Relative path with import.meta.url - Stack Overflow
Instead of applying path.resolve to import.meta.url , you should specify the relative path as the first parameter such as below
Read more >Alternatives to __dirname in Node.js with ES modules
To get __dirname (and __filename ) back, you can add code like this to the top of any file that needs it: import...
Read more >Working with file system paths and file URLs on Node.js - 2ality
In this blog post, we learn how to work with file system paths and file URLs on Node.js.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@TomasHubelbauer the chrome app and extension url is what enables the whole chrome apps and extension api support in your main background Page.
You get access to all internal API’s like Screen and so on. You can Modify any URL and so on for example you can even disable cors via that as you can intercept requests and modify headers.
I see. I also tried
__dirname
and__filename
to see if they maybe are injected into the browser context likerequire
is, but they do not seem to be. Just putting this out here if anyone finds it useful in the future.