I would like to script my example (it's an idea example it's not for this site)
Exemple (no real!) :
I open browser
I open this url : https://www.thingiverse.com/thing:5752028
I open console developper
I launch a javascript method to load in the DOM for example downloadFile() (it does not really exist on this site it is to image or more real : document.getElementsByTagName('button')[16].click() )
a file download starts (as if I clicked on a direct download link)
Save this file started
Any idea if is possible ? i thinks yes for unit test javascript no ?
Thx
No idea why i can do that..No limits language
Same :
simulate browser behaviour via Python (javascript, DOM) with no response :(
Related
i´m currently using JavaScript and HTML with eel and Python. But unfortunately when I am trying to create a file in the Chrome-Browser window (as an download) over JS i can only download it once.
The second "download" is not working.
-> Chrome just shows this (as it does when it downloads something) but then nothing happens:
When I am using Edge browser or only JS without eel it works perfectly fine!
My JS function that creates the download: (string is a json string that is generated earlier).
var jsonLink = document.getElementById("jsonLink");
jsonLink.download = "exportedToJson.json";
jsonLink.href = "data:application/json;charset=utf-8," + encodeURIComponent(string);
Ok I found a solution:
My chrome browser was blocking more than one download from "localhost:8000". So I had to go to settings and allow more than one download.
Maybe this helps someone :)
Why did I not find this earlier:
When I started my Python script, it calls:
eel.start('index.html', mode='chrome', port=8000) #starting chrome
Which does open a new Chrome Tab without the Tabbar (so i did neither see the tabs nor my favorite sites). Therefore I did not get a notification when chrome stated that download is blocked.
But after starting the eel-local webserver and open localhost:8000 in my normal chrome window, I did get a notification and I was able to allow the downloads.
-> afterwards it also worked in this eel-chrome window.
I am trying to create a script to download an ebook into a pdf. When I try to use beautifulsoup in it I to print the contents of a single page, I get a message in the console stating "Oh no! It looks like JavaScript is disabled in your browser. Please re-enable to access the reader."
I have already enabled Javascript in Chrome and this same piece of code works for a page like a stackO answer page. What could be blocking Javascript in this page and how can I bypass it?
My code for reference:
url = requests.get("https://platform.virdocs.com/r/s/0/doc/350551/sp/14552484/mi/47443495/?cfi=%2F4%2F2%5BP7001013978000000000000000003FF2%5D%2F2%2F2%5BP7001013978000000000000000010019%5D%2F2%2C%2F1%3A0%2C%2F1%3A0")
url.raise_for_status()
soup = bs4.BeautifulSoup(url.text, "html.parser")
elems = soup.select("p")
print(elems[0].getText())
The problem is that the page actually contains no content. To load the content it needs to run some JS code. The requests.get method does not run JS, it just loads the basic HTML.
What you need to do is to emulate a browser, i.e. 'open' the page, run JS, and then scrape content. One way to do it is to use a browser driver as described here - https://stackoverflow.com/a/57912823/9805867
In order to triage a problem with a web browser I am trying to determine the initiator of the XXX-xsrfstatemanager.js file (the XXX part seems to be something dynamic like a nonce) that occurs as part of a Google Authentication flow (using OAuth).
When I use Chrome developer tools, it says the below URL is the initiator:
https://accounts.google.com/o/oauth2/v2/auth?approval_state=%21Ch[REDACTED]Q%E2%88%99AJ[REDACTED]xq&as=-aBk[REDACTED]
Looking at the result of the above page see a lot of Javascript, but the string "xsrfstatemanager" is nowhere to be found, nor do I see any other javascript pages being included. Unless there is some really cryptic code that is somehow building this URL, the call is actually coming from some other page.
Does anyone know how I can get the 'real' initiator? Or if the above URL might be correct, if I can get more information like what exact line number of the file initiated the call?
By the way, while I edited the above URL for security reasons, if you go to (for example) www.quora.com and quick "continue with google" it is easy to see the flow in question.
The flow includes a redirection, which is why you cannot see the source code that initiates/references that script.
If you view the source of the original URL that is opened when you click on "Continue with Google", you will see the <script src> that references it. This works in Chrome and probably Safari -
view-source:https://accounts.google.com/o/oauth2/auth?redirect_uri=storagerelay%3A%2F%2Fhttps%2Fwww.quora.com%3Fid%3Dauth488109&response_type=code%20permission%20id_token&scope=email%20profile%20openid&openid.realm=&client_id=917071888555.apps.googleusercontent.com&ss_domain=https%3A%2F%2Fwww.quora.com&access_type=offline&include_granted_scopes=true&prompt=select_account&origin=https%3A%2F%2Fwww.quora.com&gsiwebsdk=2
From the source code -
<script src='https://ssl.gstatic.com/accounts/o/532969778-xsrfstatemanager.js' nonce="IgiKmQiLZIHDwGvce7/q6Q"></script>
You can also use tools like Fiddler to see the source code of the redirect, or check "Preserve log" in the Network panel of the Developer Tools feature of Chrome, or by going to the original URL with JavaScript disabled.
I ran into an odd issue with a bit of Javascript that is running in a Web Viewer (WV) in a FileMaker database. (For those that don't know, FileMaker is an integrated UI/DB platform which has a 'web viewer' object, which is a cut down version of a web browser that runs inside the solution. It is NOT a full web browser.)
We have had this WV+Javascript working for quite a while now, in files that are hosted using FileMaker Server (FMS). There's a button on a layout that opens a pop-out window that contains this web viewer. This web viewer is a media player, with pause/play buttons; it has some special functions for capturing the current video position and reporting it back to the database: it has some buttons and reads keystrokes, and calls back to the open FMP file to affect changes there. Again, this has been working fine when the file is hosted on FMS.
But then we wanted to make a trial/demo version of this file, and have the user run it locally or offline. In testing this offline file it was noticed that the pop-out window web viewer stopped calling back to the open file. (FileMaker Pro also registers a new URL scheme, "fmp://". This can be used to make callbacks to the database from web viewers that are inside that database. So the code was changed to use the '$' reference in the "fmp://" URL, which causes the FileMaker client software to reference the currently open file of the given name.) But even with that fixed, there was one step that was failing still.
To effect these 'callback' events from the WV+javascript to the FM file, the javascript was using this code:
window.open('fmp://' + fmdbHost + '/' + fmdbFilename + '?script=keyPressed¶m=' + e.keyCode, 'form_b');
(Here, the variable 'fmdbhost' = "$", as noted; 'fmdbFilename' =(nameoftheopenfile); 'e.keyCode'=(keypressed); "form_b" is an iframe that is defined in the HTML of the page.) This code (when it's working on the hosted environment) does not actually open a new window; that's OK, I don't want it to open a new window. It just a technique used to execute the URL and trigger functionality in the FileMaker world.
My solution/workaround, was to instead use this code:
window.location.href = ( 'fmp://' + fmdbHost + '/' + fmdbFilename + '?script=keyPressed¶m=' + e.keyCode );
This appears to work out just fine, but I'm curious to know why the original step was failing when it's run locally. This was working if the file was hosted...so why would that fail if the file is being run locally? Does it do some kind of URL verification, and not like the "fmp://" or perhaps the "$" part? If so...why isn't it doing this when using 'window.location'? (If I used the original 'fmdbHost' definition - which used an IP Address - it would at least execute the window.open() method and attempt to open the "fmp://" URL. It's just that when run locally this ended up being the wrong file - it needs to use the "$" reference to affect the currently open file.)
The specification for 'window.open()' indicates that the second parameter is a window name (sounds more like a reference to the new window). So in the original code the 'form_b' reference is attempting to reuse the iframe defined in the HTML as the conduit for the call. But is that iframe even an actual window 'reference' initially? Does something parse the DOM and extract iframes and add them to the list of current 'windows'?
I'm using FM 15.01 for testing/development, on OS X 10.11.6. Ultimately, this will have to run on Windows as well...but that can be ignored for now.
Thanks,
J
Is it possible to launch a Google Chrome extension within a website? E.g run some javascript that will launch the extensions UI?
I'm building a web-app that will allow users to take screenshots of their desktop and edit them. I've got a sample extension up and running using dektopCapture but it is an 'app' style of an extension.
It allows to select a window to stream from, then take a
snapshot within the extension UI(using a button) that is saved as an image string
My question is:
Is it possible to fire up the desktopCapture UI (the window that gets the available windows to stream from), from within my web-app, maybe a button, take the stream and place it on a canvas/HTML5 video element within my web-app?
I'm figuring that I could hook-up an event-listener within the extension and use runtime.onMessage to post a message from within my app
Notes:
If there's a more intuitive way to do this, I can go that route - e.g If I could keep as much interaction within the web-app with just the extension running in the background, that would be even better.
The extension is of type browser_action but I want it to be applicable to a single page(the app's webpage) so if it can be used in a page_action I'd prefer that instead. There's really no need to have browser_action icon if I can trigger this from within a webpage
I'm also planning to build a FF extension so any insights there are also appreciated.
So I'm answering my own question.
I've managed to get it working using externally_connectables.
The externally_connectable manifest property declares which
extensions, apps, and web pages can connect to your extension via
runtime.connect and runtime.sendMessage.
1. Declare app/webpage in manifest.json
Just declare your web-app/page within your manifest.json as an externally_connectable.
E.g I wanted to connect my app is hosted on Github Pages and I have a domain name of https://nicholaswmin.github.io, so it does a bit like this:
"externally_connectable": {
"matches": ["https://nicholaswmin.github.io/*"]
}, //rest of manifest.json
2. Set up event listener for messages in background.js
Then set up an event listener in your background.js like so:
chrome.runtime.onMessageExternal.addListener(function(request, sender, sendResponse) {
//Stuff you want to run goes here, even desktopCapture calls
});
3. Send message from your web/app page
And call it from within your web-app/website like this:
chrome.runtime.sendMessage("APP ID GOES HERE",
{data: { key : "capture"}});
Make sure that your website is correctly declared as an externally_connectable in your manifest.json and that you are passing the app-id when sending the message