Accessing visible PDF with Chrome Extension Content Script - google-chrome

I'm trying to build a Chrome extension to access the binary of a PDF in the case of a user viewing that PDF in a tab in Chrome. I thought that I would use a Content Script to get around file permission issues, and now I'm trying to figure out how to access the binary of the PDF via PDFium through the DOM. Is this possible? Has anyone found a good solution for this? I don't need to do any rendering, I just need the binary representation of the rendered file.

Related

Make chrome to read properly my own file extension

I am using on my computer a file extension I invented .gameos, in the files with this extension I put html code (html+js+css).
Whenever I try to open this files with Chrome it shows me the plain text of the html document with all of its tags, all the functions of javascript and all style properties of css.
I was wondering if there is a way to solve this problem on my single computer (sort of telling chrome how to read this files) and if there was a way to solve the problem with every computer, so each one will always show the html game and not the plain text.
Thanks in advance

Display an HTML file on Google Drive?

How can I preview an HTML file on Google Drive? I did a bit of research and it seems hosting HTML has been deprecated by Google in 2016. I tried to open the direct link of the HTML file but it downloads it and doesn't display it. Any workaround ?
Thanks :D
Ironically Google, a company built on html, still has no good solutions for handling .html files on Drive: I'm web developer! If you create a .html file within any text editor (Mac, Linux or MS) and save it with a .html extension (e.g. test.html), that file is now a Browser file, not a text or Doc file. G-Drive was created to be a cloud replacement for MS Office suite of products (Word, Excel, and so forth). It will even save a .txt (or text) file, and display it back as such.
However, a file dropped in Drive (via the Chrome browser) with a .html extension; if you simply click on it, it will be opened by/in Docs, and displayed therein as a web page (and poorly too, since it cannot connect to the styling of the .css file). If you right-click on it, and select "display", it will give a similar display only without opening it in Docs. If you right-click and select "download" it will download in .doc format. Yes, worthless! I copy the html, code and all from the file on my PC, and paste it into a blank Doc file, which is OK for a backup of that file, plus it will spell-check and all, but it is not an easy way to cloud save or sync. And, it cannot open the browser to view it, because it is internal to (or already inside of) the browser. The only accurate way to preview a .html file, is for the file to be external to a browser (any web browser), and then opened inside or with that browser.
To repeat: If you simply click on it, it will be opened by/in Docs, and displayed therein as a web page (and poorly too, since it cannot connect to the styling of the .css file). If you right-click on it, and select "display", it will give a similar display only without opening it in Docs.
I am not exactly sure what you mean by display. If you just want to preview a file in google drive open it and see its contents then the only types are
PDF, Microsoft Office file, audio file, or photo.
Just double click your html file you can preview it in drive.
please see View and open files
If you are actually talking about web hosting a html file then. Hosting of HTML files from within Google drive was Deprecating in August of 2015 and shut down completely in August of 2016 so you can no longer host HTML files directly via Google drive Please see Deprecating web hosting support in Google Drive
Alternative would be to use Google Domains to host a site that way this option is not free as far as I know.

Get downloadhistory from Selenium

Is there any way I can find out what the latest file Selenium downloaded was, and from where (what URL) it was downloaded?
I am fetching files from a large number of sites (that I do not control) by clicking on elements, and my problem is that I do not know how the files are downloaded. Sometimes it is just an <a> element, sometimes there is a Javascript event attached to some element, or form (not always obvious from inspection), and so on, and so on.
So I though the easiest would be to just do my clicks, and then check what landed in the download folder. But then I have no idea where that file came from, and I also need to store the url.
For files that can be displayed inline, I can, of course, open them in the browser and get the driver.current_url. This is very convenient for file formats where it actually works, so if there is a way to force e.g. Firefox or Chrome to open all files inline, that would also be an option. (I am aware of one such extension. That extension, however, requires some user interaction in a OS file dialogue window, and that seems like overkill here)
Possible solutions
Firefox: Read moz_downloads from downloads.sqlite, in the FF SQLite DB
Chrome: Read the corresponding SQLite db for Chrome/ium
Write browser extensions that modifies the mimetype of visited pages, so that all files are opened as plain in the browser, and the URLs can be accessed from there.
How I understanding selenium it only insert js to page, that mean that you can interact only with web page but not with browser futures.
But you can do like in this post How to access Google Chrome browser history programmatically on local machine if that files are in download history you can find them there.

How extension get the text selected in chrome pdf viewer?

I wrote a chrome extension - english dictionary. You select word, the definition appears.
It works well, but I counter a problem. It seems there is no api of chrome pdf viewer supplied by google.
How can I get the word when i select a word in pdf using chrome pdf viewer?
I will be appreciate if you could help me.
You can get selected text using the context menu. In your background script, adding these lines will allow the user to right-click and do something with the selectionText.
chrome.contextMenus.create({id:"lookup",title:"Lookup %s",contexts:["selection"]});
chrome.contextMenus.onClicked.addListener(function(sel){
console.log(sel.selectionText);
});
Grabbing this text works fine with PDFs, whether part of the extension, or not.
However, you cannot inject a script into a page starting with "chrome-extension://". If this is how your extension works, that will not be (directly) possible. But getting the selected text, and doing something with it still very doable.
As an alternative to requiring script injection, see the notification api, which allows a small message to popup, which could contain the definition of the word.

What are possible ways to read and display .docx/.doc file in editable mode

Using HTML5 File API I am able to read text and XML files without any problems. I have tried to read the .docx/.doc file with the same code and that was not working. In my chrome extension I need to open a .doc/.docx file in editable mode in Google chrome. I am really waiting to know all the possible ways to achieve this. I found some extensions like Google docs viewer etc.. But they are opening files in preview mode. Please help me on this
The .DOC file is binary, and DOCX is a zip file containing a whole collection of XML files that make up a Word document, so neither can easily be read by your straight XML reader.
I don't think there are any native extensions or bits of code for Chrome to edit DOC or DOCX files, so you'd have to write your own - presumably, that's what the extension you're considering would do. You can use the Google docs viewer as a jumping off point - there's no difference between "preview mode" and "edit mode" other than one writes back to the file and the other doesn't. And you'd need to add the controls to modify the document on screen, which may be the larger hurdle.
If you can give some detail on where exactly you're stuck, that might help the community point you towards a solution, but a general "nothing does this for me" is likely to result in a little less help.
Good luck!
you can use jquery for this.
you can use typewith me which is generated in jquery where you can import/export docx,doc.pdf,etc.. files check type with me and private pad
you can use its jquery code for your use as it is opensource.