Need to send information from chrome to external app - javascript

I have an app (software in my windows) which I can do whatherver I want with it and I need this app to be notified when some JS code is run inside chrome. Ok this is not easy.
So I came up with this idea: when I want to notify my app (running on my windows) to do something, I just downloaded a cacheable file (using js) to my chrome browser. THEN my app can check every 10 seconds the "C:\Users\PC\AppData\Local\Google\Chrome\User Data\Default\Cache" directory to know if a file with a specific size was created.
This is working flawlessly! But I wonder if you guys would recommend any other method to send a command or anything from JS code running inside chrome to an external app running in windows?

Related

How do I inspect an Electron app's DOM from a script?

I have an Electron app running on my computer (Slack). I would like to run some JavaScript that reads HTML DOM of this app. Is this possible? If so, is there a "getting started" somewhere?
In my mind, since Electron uses Node.js to host HTML / JavaScript, I can possibly read the DOM. At the same time, I could see this not being allowed because it could be a security risk. I'm ok with the security risk since it's running on my machine. So, I assume there would be a UAC prompt. Still, I'm just trying to figure out how to read the DOM from an external script if possible.
Thank you
From my understanding you want to inspect or manipulate some HTML of a electron app which is installed?
This is how I figured out how to access (on Mac OS) using Slack as an example:
Go to your Applications Folder -> Slack -> Right click "Show Package Contents"
Go To "Contents->Resources -> app.asar.unpacked"
You can check out how for example parts of the slack app work.
I tried this also with GChat app and they have an app folder. Technically speaking, you could add a script or something into the index.html / index.jade (slack) and hijack into the main.js or index.js scripts.
For example I was able to search for BrowserWindow Object inside the Chat App of Google Chat and add .webContents.openDevTools(); easily.
Yet any solution involves manual work.
For example in the main.js of of GChat I beautified the code, I searched for the Electron method buildFromTemplate and found the specific function where the View Menu is created. I simply added the following to that
{
role: "toggledevtools",
label: "Toogle Dev Tools"
}
And at the end I was able to easily toogle devtools (seen in the screenshot)
If you are thinking of accessing DOM through console (dev tools) like in a browser, then it's something you cannot do. Because dev tools are available only in development environment, once you build it, you cannot access it.
So running a script may require the electron app to include the script in the source code :
<script src="your-script.js"></script>
So if they included your script in their app, then you could change the content of the script to achieve what you are looking for.
You can add your script into the page (before it loads) and have it there to interact with any page you open in electron.
The easiest way to do that is using preload paramater of new window.
Bear in mind, that you can even make connection with your nodejs script so there is really nice way of communicating with opened pages and your own script in node/electron.
More here: https://electronjs.org/docs/api/browser-window
preload String (optional) - Specifies a script that will be loaded before other scripts run in the page. This script will always have access to node APIs no matter whether node integration is turned on or off. The value should be the absolute file path to the script. When node integration is turned off, the preload script can reintroduce Node global symbols back to the global scope. See example here.

Preventing chrome/windows from downloading _Thumbs.db

I created a local web app that just displays images and PDFs on a loop kiosk style. It has a basic Node.js http back end that feeds file paths to client browsers and the browsers use embed elements to display those files.
The issue is that when the client has run through the files provided and is told to reload chrome (It looks to be chrome that's doing it at any rate...) downloads a _Thumbs.db file. This app is meant to be a full screen kiosk and I would rather not have the downloads bar or any downloads prompt be present while it's running the slideshow.
I have disabled all the options for thumbnails on the windows side, but oddly enough it is a chrome download prompt that is the issue.
Can I prevent these files from being downloaded? If-Not any Idea how I can prevent Chrome from throwing a download prompt up?
Thanks in advance.

Reading a file from a folder when it gets created using nodejs

Following operations are going to take place :
A text file is created using a java program and it gets stored in a folder
The file needs to be read and displayed in the text box which is present in the browser UI.
For this to happen, the java script needs to check the folder till the text file becomes available and then read it and display it in the text box.
How will the javascript come to know when the text file is available in the folder and how is it going to read it and display it.
We are using Nodejs as the container and Ember Java for the web framework
This is only possible if you run Ember locally rather than served from a web server.
Create an in-repo addon in your Ember app. It will have Node context.
Have the addon watch the folder for changes. Read the file when it's available
Have the addon run a web server that responds with file contents when it's available.
Configure your app for long polling the web server.
If you do need to server the app from a web server, then you're out of luck. You can try running a desktop app on the computer that watches the folder for changes then sends the file contents to the server. Then the app can request the file from the server. That's more elaborate.

Does google chrome app development allow you to add html and javascript to the locally stored files, depending on user

I want to create a web app platform that runs locally on the users computer.
I am considering using google chrome's app process to make this work.
I am having trouble understanding, wether google will let me do this. so the user would have to download the main chrome app , which contains the base html and javascript code, and within the app be able to download and store locally with in the app new html and js code.
So in other words I want to create an app that allows users to download and install apps from my own app store, and have them run within the chrome app.
Does google chrome app development allow this?
if not what are my alternatives for creating an app that needs to run on a browser storing all files locally?
You can download HTML and CSS as much as you want and then use JavaScript to modify the DOM accordingly. It's not set up as any kind of system that lets you substitute pages, and there's no navigation within the app (using A elements), but you are free to modify the DOM.
There's no way to add any JavaScript to what's initially in the app, as eval and the other code-executing functions are disabled. You can certainly add SCRIPT elements to the DOM, but the files they reference have to have been part of the app at the time it was installed.
Having said all that, you can implement the app as an interpreter for some language and then download programs written in that language. It's just that none of the code can be direct Chrome App code, nor can any code you download (regardless of language) make direct Chrome API calls.
Have you looked at the HTML5 Filesystem API? You can fetch a file and reference it later. You also need the add the "unlimitedStorage" permission to manifest.json.
http://www.html5rocks.com/en/tutorials/file/filesystem/

Tomcat in Eclipse: Edit Javascript without redeploying

I am working on a Java application (which runs on Tomcat) using Eclipse WTP. For development I have configured my tomcat server in Eclipse and use the "auto publish" feature.
This works for .java files (compiled files are getting published).
Its also fine for working in jsp. In this case my edited jsp file is just copied to the server directory without redeploying my application.
However it does not work with javascript files. Everytime i change a .js file my application is redeployed and i have to wait a few seconds.
Is there any tomcat option i am missing?
Thanks
Doubleclick your server in the servers view, click on the tab modules at the lower bound of the servers property window, select your web module from the list, click the edit button, uncheck "auto reloading enabled", click ok, save your settings and restart the server.

Categories