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

[Chrome] Need option to open PDFs by default #8

Closed
Adr0it opened this issue Jun 20, 2023 · 7 comments
Closed

[Chrome] Need option to open PDFs by default #8

Adr0it opened this issue Jun 20, 2023 · 7 comments
Assignees
Labels
chrome This issue affects the Chrom(ium) variant enhancement New feature or request

Comments

@Adr0it
Copy link

Adr0it commented Jun 20, 2023

Hello, first of all, I really like your pdf viewer. Originally, I was trying to create an extension with Chrome's default pdf viewer, and I basically couldn't access any of the html I needed, so I'm using this instead. It's funny because all I wanted to do was make a bookmarking extension that gets the title, current page, and first page canvas thumbnail, but it all turned out to be this complicated. I'm more of a hobbyist, so I don't know if I will successfully be able to modify this extension to communicate with my own, but theoretically I should be able to looking at the Chrome documentation (messages between extensions).

The only small thing I would like is for the extension to open the newViewer on its own whenever an offline pdf document is detected like how the Adobe Acrobat PDF extension functions. For my own personal use, I basically modified the code to have a content script signal the service worker to open the newViewer and close the original tab.
image

@shivaprsd
Copy link
Owner

shivaprsd commented Jun 23, 2023

@Adr0it Thanks for stopping by! Can you explain how automatically opening offline PDFs would help your bookmarking extension? I am not able to see any connection there. 😕

Can you also show me how you are injecting your content script? My main concerns here are permissions and consistency. We would need wide host permissions to run content scripts in all file:// urls, and auto-opening only offline PDFs creates different behaviours for offline v/s online.

In Firefox doqment auto-opens all URLs. This is because there the intent is to replace the default viewer (as doqment is only a modified version of it). In Chrome the design is different both due to technical limitations of MV3 and for letting users use doqment as a second PDF viewer without invading their privacy.

@shivaprsd shivaprsd added question Further information is requested chrome This issue affects the Chrom(ium) variant labels Jun 23, 2023
@Adr0it
Copy link
Author

Adr0it commented Jun 24, 2023

The feature of automatically opening offline PDFs is just convenient in my opinion. It doesn't have anything to do with my extension.

Here is what I did. Just put pdf file in manifest (you can also add https:///.pdf for online sources) for when the content script runs. The content script then sends really any random message to the service worker, and the service worker simply opens the viewer and closes current tab (which has default pdf viewer). Not really the best solution, but it's convenient.
image
image
image

@shivaprsd
Copy link
Owner

Thanks, I got your intent now. I guess this could be done a bit more neatly with Declarative Net Requests redirect rule, or even chrome.tabs.update() instead of opening a new tab.

The problem with this is that we are relying on the .pdf extension to detect PDFs, which may not always be the case. This is why currently we check document.contentType (Chrome) or MIME type in response headers (Firefox). This is something that neither match patterns nor DNR rules can currently handle.

Even if we find a way, this will inevitably need a permission escalation, that can result in the extension being temporarily blocked on the Chrome Web Store, pending a manual review. Yet I understand the desire for convenience, so let me edit the title to better reflect the general case. This has to be implemented thoughtfully.

@shivaprsd shivaprsd changed the title Auto open newViewer when file:// recognized as pdf. [Chrome] Option to open PDFs by default Jun 24, 2023
@shivaprsd shivaprsd changed the title [Chrome] Option to open PDFs by default [Chrome] Need option to open PDFs by default Jun 24, 2023
@shivaprsd shivaprsd added enhancement New feature or request and removed question Further information is requested labels Jun 24, 2023
@shivaprsd shivaprsd self-assigned this Jul 15, 2023
@shivaprsd
Copy link
Owner

shivaprsd commented Jul 15, 2023

I figured out a way to do this with dynamic content scripts so that the permissions can remain optional. Now on dev branch: 85f740e.

@Adr0it It is loosely based on your idea, so thank you! Can you please try it out and get back? Just right click on the extension action and switch it on via the menus (first the "Always allow..." menu followed by the other).

@Adr0it
Copy link
Author

Adr0it commented Jul 17, 2023

Works amazingly, nice. I don't have a clue how to navigate git to get dev branch updates, so I just kept sticking files together until it compiled the Chrome extension, and it worked at last.

image

@shivaprsd
Copy link
Owner

shivaprsd commented Jul 19, 2023

@Adr0it Thanks! Can you give your feedback on the interface, i.e. having to go through two menus to enable it? I did it that way to make the code cleaner, and enabling it requires enabling the first menu anyway. Did you find it cumbersome? Would you find it confusing if I had not told you exactly what to do?

P.S.
For your future reference, you can check out the dev branch like this in git:

$ git clone https://github.com/shivaprsd/doqment.git
$ cd doqment
$ git checkout dev

Or, if you don't use command line, you can first select dev in branches on the GitHub website interface and go to <> Code ➡️
Download Zip to get the dev branch files.

@shivaprsd
Copy link
Owner

Fixed in v0.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chrome This issue affects the Chrom(ium) variant enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants