How do i send a JavaScript command to a web browser from an external c++ application?
At the moment what i am currently doing is saving the HTML file locally, modifying it, and send a command to refresh the browser from my application.
This might be trivial for some, but I was wondering if i can send the JavaScript command directly to the web browser and see the changes happen without modifying the source code.
I am currently using the following: Firefox, Chrome and IE.
I tried with modify files from within my application using QWebEngineView but it takes a ridiculously long time to load the pages and some webpages are complaining that the browser is too old.
Related
I have six devices on/above my desk:
A 4k TV
An Ultrawide monitor
Two laptop computers
An iPad
An android phone
All are connected to the internet and browsing mydomain.org/page, an html page that I am editing using one of the laptops, which has a full page of code. When I press a button on my Wacom tablet that I rerouted through Wacom smart actions to run a script, my code is uploaded over FTP to my server. Right now, I have to reload every page on every device to see the updated results. I want to make a javascript to run on my site that has a LiveLoad() global function. When I execute this function from the DevTools command line, the script stores a cookie that the device is a debug device.
All pages with the script will now enable a small icon over the page that when set to 'live,' the script will open a connection through secure web sockets with an update server that stores up to 10 connections (perhaps only from approved IPs, so that only I can use this on my live site), each registered to the page they are browsing. When I update mydomain.org/page or other pages, my script securely opens a connection and POSTs a secret code to the update server, telling it to send a message over web sockets to all connected debug devices with that page open. On fast internet, this truly will be the ultimate website building setup if I can just overcome this design hurdle.
What I don't want:
Anything more than a single php script for the server-side implementation. Shared hosting. No root access. No Node. No fancy crap. Single PHP files are the only option.
Bloated javascript addons. Bare minimum code for receiving a single type of message (an update is needed) is all I need. Perhaps later I can make it more robust with a second type of update (a hard update) where a php script processes all the fonts, scripts, images etc on a page and adds a random query string after them to force a hard-reload of all page resources.
How can I achieve this? Where to start with php web sockets? The internet has proven to be a cynical wasteland of bloated php libraries that require installation in a node enviornment to freelancers struggling to make scripts off of the 2013 websockets API documentation, with no good, simple solutions around.
Is it possible to use C# to render an ASP.NET view on the server side and save it as a PDF, preserving all the visual elements that involve CSS and Javascript, exactly as it renders in Chrome? The Javascript includes the latest versions of the standard Bootstrap and d3 libraries, as well as code using d3 to draw SVG charts. The page's CSS heavily uses Bootstrap.
I've tried a few things including IronPdf, but it completely destroys the formatting no matter what options I have tried. The only good results I've been able to get are by actually viewing the web page in Chrome, trying to print it, and saving it as a PDF that way. I'm trying to basically get exactly the same results using backend C# code to generate the PDF, without any user interaction needed. Can this be done? If it's impossible to render perfectly as a PDF I would also be open to other visual file formats that preserve the appearance of the web page.
You can run any install of chrome in headless mode and send it a command to print:
chrome --headless --disable-gpu --print-to-pdf=file1.pdf https://www.google.co.in/
I did this a couple of years ago. I created a microservice that took a URI, a test javascript, and a massage script then returned a pdf.
Test Script:
The test script is injected into the page and is called repeatedly until it returns true. The script should verify that components are in a properly loaded state. (This could be skipped by simply using a long delay prior to printing the pdf)
Massage Script:
The massage script is not required. It is injected into the page to alter the javascript or HTML prior to printing the pdf.
I used this heavily to load the entire user JOM including all Angular data stores (NGRX) since the user context was not present in the server-side Chrome instance.
Delayed Printing:
Since this is not a feature supported by chrome, I made an endpoint on my server that would hold a GET connection indefinitely. A script referencing the endpoint was injected into each page to be printed. When the Test Script returned ready, the code would cancel the script request by changing the script tag src to an empty script file that would return. This would conclude the last item that Chrome was waiting on and the documentready event would fire thus triggering the chrome print.
In this way, I was able to control Chrome printing on complex authenticated pages at my server.
I understand that there are ways to listen for a local [on the same computer] file being modified, moved, or deleted in python. However, there doesn't seem to be any easy way of telling if an html file has been opened by the browser, because javascript and html aren't capable of editing or locking files by themselves, as far as I can tell.
The only solution seems to be opening a websocket connected to the python application (even though python is running on the same computer) in javascript every-time the web page is opened, but I'm wondering if there is a better way, preferably one that doesn't "poll" and instead is event based since I have a large amount of files.
I believe that you can send an ajax request to python when the page loads. If you are using a PHP backend, you can have PHP edit a file every time the page is loaded and you can then view this file using python.
Could somebody advise me on which project type should I use to develop client side of web-based app (HTML + JavaScript) for Visual Studio 2013?
I tried to create New, Web Site, ASP.NET Empty Web site, then manually added all .js files to the project, but this is not exactly what I need, because I am working on a client-side code only, and the Web server is not IIS.
Of course, when a script error occurs, I can select “Debug using selected debugger”, manually choose my project and jump into debugging. However, this is only a half-solution.
First, I cannot start debugger with F5 – it launches web page connected to local IIS instead.
Second, I have duplicate source trees in solution explorer- the debugger does not match my source files with files loaded with web pages.
I have also tried New, Other project types, Visual Studio solution, Add existing Web site, and played with Start Options, but without much success too. It launches page in IE, but with script debugging disabled (???), and it does not start the debugger anyway.
Is there an appropriate project type to write and debug JavaScript for IE?
PS: When installing VS, I selected C++ development, as my primary settings, which might hide some useful Web development features. And I would prefer not to change this.
UPDATE: Problem #1 (starting with F5) was solved by setting IE as default Web browser (I have used Firefox). After specifying “Specific page” in Start options F5 starts the page under debugger.
Is it possible to debug scripts under IE, leaving my favorite browser as default? If I specify “Start External program” and set “iexplore.exe” with page url, it launches the page but does not allow me to debug it.
you have a bunch of questions in here, but let me try answer them.
To develop client-side of web-based app, Create an ASP.NET Empty Web site and manually add HTML + JavaScript
If the Web Server is not IIS, then you can change, right-click on your project in VS-2013, and in properties,check Web properties.
To Debug your HTML and JavaScript in IE, then follow this:
you have to enable Script debugging in IE as follow:
let, if you have a function named FirstFunction() in your HTML page then
<script type="script/javascript">
function FirstFunction()
{
debugger;
alert("Debugging now");
}
</script>
I have created a Java program which takes some command line arguments to run. I need to make a browser extension to the program so that the program can be opened with data from the browser.
I know Javascript does not allow any local file access, but there are programs which doing the task I needed.
Examples are Internet Download Manager which has the browser extension for running it receiving command line arguments from the browser. Obviously extensions for most of the browsers including Chrome and Firefox are made using Javascript? Is there any way to do local program execution via JavaScript (I think there's a way surely)?
You can't directly run anything from your JS sandbox on client PC (just think about security risks!) There's other method however: Make your application register itself as protocol handler when it installs and use links with this protocol on your pages (think how e-mail clients serve mailto: or torrent clients serve magnet: links). Since you control both sending and receiving side, you can pass pretty much any information in those. You can find Windows example for registering a handle at MSDN. Should you need it for any other system, I'm pretty sure searching for "system_or_gui_name register protocol handler" will show you desired result among the first.