Open localfile without using <a href>
Opened this issue · 2 comments
Hello,
I've been able to use the addon like this <a href="file://PATH_TO_MY_FILE">LINK</a>
.
However, I have a need which is to open the path from javascript.
On chrome / edge, I do window.location.assign(file://PATH_TO_MY_FILE)
and it will redirect the user opening the files (using another addon, localexplorer), however, doing the same in firefox doesn't work, the addon isn't triggered.
tried also: document.location.href = 'file://PATH_TO_MY_FILE'
which is not working
Is there any way to do this ?
Thanks
Regards,
@yeyeric No, that is not supported by the extension yet.
Thanks for creating the issue. So there are the following points to check:
window.location.assign
supportwindow.open
support- Content script: Add the event listener for the JS Api (if the option is enabled)
- Option "Enable JavaScript support" in the setting to enable this (disabled by default)
I haven't worked on that feature. But there is a similar issue #158.
The thing with the option is a security concern because a malicious page could trigger like 1000 files to open - which would block the victim's PC.
But I think it's OK to add with the option and by using the whitelist it is safe to add.
A basic version is working on branch js-filelinks
All the mentioned points are added. I do some more testing next week. If you like you can test the version on that branch with npm install && npm start
window.location.assign
and window.open
is working. The event listener I'm using is looking for window.onerror
and checking if there is an access denied message for file://
. If it detects the file link it will open the link without an error message in the console.
I'd prefer to use a different event handler and not the error handler. So this is not perfect but it works.
If the option is disabled you'll get the error message in the console and the listener is not attached in the content script. The settings change requires a page reload.
The "Enable JS file link support" is disabled by default because most users don't need it and it's more safe to have this disabled.
There is a basic JS example in the webserver folder. It looks like the following:
Reveal is also supported if you add a ?reveal=true
to your link e.g. file:///C:/tmp/existing_file - Kopie.txt?reveal=true
.
The new settings page looks like this (German language):
Please check the text for the English locale for the new option. Is it OK? Grammar OK, is it clear what the option is doing?
You can find it here.
I need to document the feature in the readme.
The only case that is not working is if the JS will trigger the file link open in the DOMContentLoaded
event. Both functions will not work. I need to check if I can attach my onerror
handler before DOM-ready event.