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

[Extension] Embed file path into URL for reloading #95

Open
minerharry opened this issue Feb 15, 2024 · 5 comments
Open

[Extension] Embed file path into URL for reloading #95

minerharry opened this issue Feb 15, 2024 · 5 comments

Comments

@minerharry
Copy link

Feature Request: Embedding the path to the file you are viewing into the URL would make it so on reload, close/reopen, and bookmark you could save and automatically return to the file you were viewing. Especially relevant for the firefox extension where the file:// syntax doesn't work.

@RussCoder
Copy link
Owner

In Chromium-based browsers it's already so. But in Firefox I think it's not possible. One cannot open a .djvu file in Firefox with a double click, and there is no "Allow access to file URLs" option.

@minerharry
Copy link
Author

How about as a query string? (If this is stupid forgive me for my limited knowledge of webdev)

@RussCoder
Copy link
Owner

It's not about the URL, it's about the API provided (or not provided) by the browser. I can edit the URL as I want, but I cannot get a file path, and even if I get it, I will not be able to load the file.

By default, JavaScript has no access to the file system. So websites cannot scan your hard drive. When you upload a file, only its name is exposed (and some metadata), but not the full path. However, even if the full path is known, there is no API to load the file (again, for security reasons). Thus, JS can read only files that have been explicitly uploaded by the user.

Web extensions are JS applications and use the same browser APIs as websites do. But there are some additional web extension APIs too.

In Chromium-based browsers, there is a separate option "Allow access to file URLs". It should be enabled manually, after the extension has been installed. If the user has enabled it, and opens a file with the browser, then the browser initiates a request to the file using a file URL. This request can be intercepted by the extension, and using the file URL the extension can load the file.

In case of Firefox, it doesn't work. If you try to open a binary file with Firefox, it will show you the download dialog. It doesn't initiate a request, so the exception cannot intercept it. And there is no "Allow access to file URLs" option too.

@minerharry
Copy link
Author

Ahhhh I see, very annoying. Is there a way to hint at the file open dialog to open on the previously selected file, or is that all controlled by Firefox as well?

@RussCoder
Copy link
Owner

It turns out there is an API to do it, but it has not been implemented in Firefox yet, and it allows an app to select the initial directory, only if the app has already got a file handle from that directory. That is, if you open several files on the same page, then this API can be used. But if you close the page, all file handles will be lost.

@minerharry minerharry changed the title [Extension] Embel file path into URL for reloading [Extension] Embed file path into URL for reloading Feb 28, 2024
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