Closed Adr0it closed 11 months ago
@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.
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.
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.
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).
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.
@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.
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.