I would like to know if it possible to run a JavaScript script continuously in the background of a CefSharp application, having it start upon the application first opening and run until it is closed.
Specifically, I am utilising a JavaScript-based eye tracking library. Upon the application opening, the user needs to calibrate the eye tracking. Once calibrated, this script needs to run in the background sending tracking information to other pieces of JavaScript.
Currently, all JavaScript is loaded and executed on the main frame. So, when the user navigates to new pages using the browser, execution ends and all the JS is re-loaded and re-executed upon the frame loading again. This makes it so that the user is prompted to re-calibrate the eye tracking on each new page load, whenever I need it to be performed only once.
The JavaScript files that are re-loaded need to be re-loaded, as they interact directly with the DOM and so need to access the information of newly loaded pages.
It'd be preferable for these re-loaded JavaScript files to be able to interact directly with the continuously running background code, but it is also possible to establish communication through a WebSocket.
Currently, I am not sure if this is even possible and if it is I do not know how to go about it.
I attempted to spawn a new separate frame that is never re-loaded and running the background JavaScript there - but I did not get very far. The application I am building on does not currently support multiple tabs (there seems to be no UI available for it, etc), hence why I found it difficult to spawn a new frame that the user can interact with briefly.
Apologies for the lack of code snippets - many thanks in advance.
Related
I am trying to create a 3d model viewing website for various student projects. Currently pulling from the 3js library to reference OBJs and MTLs on server. The idea is that you can click on the left box of each student wrap div to open a modal with a 3js file viewer.
This works 100% of the time the first time you view a model (first execution of render function), but opening and closing models will often result in MTLs being dropped, see here. Testing on multiple devices it seems that devices with faster internet connection/more processing power can actually load more files before corruption begins. In addition, not rotating the viewer seems to allow more files to be opened.
No error messages for the JS can be found in the Inspector. Messages sent from the 3js library files, however, show numerous errors any time a second/third/nth file is loaded without JS refresh. Putting in location.window.reload() in the exit function refreshes JS each time and fixes the error, but that causes a whole other set of problems.
The site with all source code and files can be accessed here: biszweb.
I will be able to provide more information is needed.
Please advise and thanks in advance.
Resolved. Certain parts of 3.js need to be reloaded after rendering a model. Simple fix would be to insert a js reloading script.
Basically my issue is I have a web browser (Chrome) running Qminder monitor displaying a queue but I want to show other stuff on the display at the same time.
The idea is that when someone is called, Qminder refreshes the browser window to show the update.
Is there a way to write a script that can monitor 24/7 for this browser refresh and switch the browser window back to the foreground?
I will already be making a script that will switch between the digital signage and the Qminder queue on regular intervals, but figuring out this key part of having the screen show the person being called is the most important part.
In the browser, we don't actually reload the page, we also listen to WebSocket events and add people into the UI dynamically.
You can write a script directly against the Qminder API, which will send you WebSocket events when someone is called. Alternatively, you can receive webhooks when you have a public-facing web server.
From an user experience perspective, it would be better to show the queue at all times. This shows your visitors where they are in the queue at a glance. For additional signage, we suggest you add another screen. :)
You should check out the Qminder API doc. You'll find useful information under the Events and Webhooks section. (Note, that the Events section is geared towards using the Qminder Javascript library)
As for showing and hiding applications: Hide Application. You can integrate it into a non-AppleScript solution via the osascript(1) program.
I wonder how sites like SoundCloud work: you play a song and it keeps playing even if you move to another page without stopping
Any suggestions?
The only way I can think of is to build your app, or at least the parts of it that need to bo continuous, as a single page.
In practice, this means that only one HTML document is loaded. When, say, a link is pressed, the browser action is intercepted and prevented and the browser behaviour is faked by javascript.
Consider a website consisting of pages A and B. Normally, when a link pointing to B is activated, the URL is changed and the browser calls the server, requesting B. In a single-page application, however, this is interrupted by a javascript function, which changes the URL using the History API, and then displays B in a way that doesn't require a new document being synchronously fetched from the server.
There's a couple of ways to do it.
Navigate to a new page
If you do that, a whole new JS execution context is created for the new page, so you can't keep the function running. What you can do however is to "resume" execution in the new page. For this you need to save the state of the old page either on the server or in some client storage that persists between page changes (cookies, localStorage, etc).
Fake navigation
This is the most user friendly way - you turn your website into a web application. You no longer have multiple pages, so when user wants to change what he sees in the browser (like go to a new song), the app simply changes the appropriate area with the desired content. This is a complex topic that should probably be researched in itself, not explained in a SO answer. Go ahead and google "single page application" and you should find plenty of resources for it.
Technically you never change the page when you are using souncloud. You always stay on the same page and only the parts get changed which are actually changing, so you never reload the whole page. That's why they can keep the music playing: They just never remove or change the actual player. If you are wondering why the URL in your browser is changing if you never leave the page: They manipulate your history entries.
If you are interested in creating an application that behaves similar you should checkout frameworks like Ember.js or Angular.js. TodoMVC Gives a nice overview of those frameworks.
I was wondering if there's any way to attach a js lib to an external webpage after the page has loaded?
To provide a simple example, could I load www.google.com into IE and somehow display the webpage with a green scroll bar?
I would like this process to happen automatically on each page load instead of having to manually execute this process on each page load.
I am assuming that you are talking from a web developer's point of view.
I don't think it is possible without any hacks.
This would also be a huge security risk, because loading javascript code on an external website means that the code can potentially do anything on behalf of the user. It can capture keystrokes, take screenshots, note down passwords and do a lot of illegal stuff.
So instead of this, you can create a browser extension (add-on) which will have to be installed by user's permission (and his knowledge), and can run any code on any page (if the user allows it)
In traditional web application i generally write JSP which renders html code to browser and communicate to server using form submit or through Java script. This generally involves page transition from one to another using browser refresh many times.
Now with the improved HTML5 i still can use the same approach but i want to achieve more of a desktop application look and feel which means no browser refresh. But i am really confused how it can be achieved.
Do i need to write a big single html5 file which contains all the web application code and show or hide divisions using java script that we need to show at that point of time. Communicate to server using java script.
Or, Just have a minimal first html5 page where user lands for the first time. Later on create all the HTML5 content dynamically using java script and communicate to server using java script. This looks more difficult.
Or, is there a way we can move from one page to other without the effect of page loading/refresh etc.
In general using HTML5 what should be the approch?
For example of a shopping cart, the first view to the user is list of items to purchase. Then user moves to next view such as details of an item. The next view can be payment.
If you have some resource or example to explain it, it would be great.