"Silently" invoke helper application using Javascript - javascript

Can Javascript cause browsers generally (and Chrome for Mac in particular) to invoke an external helper application for a URI without opening a new tab/window, or navigating away from the current page?
The context is that I am developing an extension for Chrome that occasionally needs to invoke particular actions outside of the browser. Using the rather neat trick described here, the extension only need open particular URIs to invoke suitable AppleScript.
However, how should one open such URIs from a script running in an extension's background page? I don't think XMLHttpRequest will help, as Chrome won't (shouldn't?) attempt to use an external helper application for XHR; nor does it appear that setting window.location.href has any effect on such a background page (it is not a problem if the background page is unloaded).
My current solution is to open a new window, but it's unnecessary and rather distracting for the user.

There are a few options here:
You could write an NPAPI plugin.
You can use a WebSocket client in the browser, and run a local server on your desktop. That way you establish a tunnel to your local machine to do pretty much anything you want there.
I did this for relaying global media key presses to control web-based music players and wrote it up. Source here.

I just realised I can do this with an <iframe/> in the background page. Très simple!

Related

Button Navigation in Windows 8 App

I am really new to Windows 8 App Development.I am creating a Windows 8 App in which I need to click a button and open another page. I am developing this windows app using HTML/CSS and Javascript. How can I navigate to another page using a button click? I have tried several with window.ways which I can use with HTML/Javascript for Browser web pages. But non of them are working. Is there a special way to do this in Windows 8 App development? Can anybody please explain with an example.
Thank you.
I could guess that maybe your problem is in understanding the different contexts? A page can run in the "local context" which gives it the permissions of your app and access to the Windows 8 API. A page can instead be run in the "web context" in this context it does not have access to the Windows 8 API but can execute remote code.
Basically, you start in the local context...code that is part of your app. From there, you can link to pages in your app's package (these would run in the local context). You could also link to things outside of your app package (these things would run in the web context). The confusing thing is when you link to something in the web context. Basically, since replacing the current page/screen with the web-context would make you lose all access to the Windows 8 API, when you link to something in the web context, Windows 8 won't replace the screen with that page, instead it will open up IE10 and load the page in there; That way you don't lose control of your app. The trick to loading stuff in the web context is to load it in an iframe which is in the web context. But you always need to keep the main page itself in the local/app context.
For your reference:
Urls starting in "ms-appx:///" load in the local context.
Urls starting in "ms-appx-web:///", "http://" or "https://" load in the web context.
As far as I remember, if unspecified, links are in the same context as the page they are in.
In terms of how to do it...you should be able to use <a href="..."> as well as the usual javascript ways. It's been a while since I've coded for Windows 8, but I don't remember that part being different from how I did things in normal web development.
Unless of course you are talking about the PageControl object or the navigation template. So many things. Either way, I strongly recommended getting the free book "Programming Windows 8 Apps with HTML, CSS and Javascript" by Kraig Brockschmidt. It's an easy read full of examples and I'm sure that will solve 99% of your questions if you are new to this.
So you tried the
href="____.html"
try dropping the ".html" so it is just
href="____"
And do you have the controller to handle it when you tell it to go the page?

Start a background process with javascript

In general I am aware that one cannot call system libraries or dll's from javascript in browser. But in many of the application's I see browser starting other processes. For example:
As soon as I open Google Plus, it starts the googletalkplugin.exe (from folder C:\Users\Jatin\AppData\Local\Google\Google Talk Plugin) in the background. (Can be viewed in Resource monitor)
The same with facebook video chat. For the first time, it asks me to install a plugin and later when I start a chat, it starts a process.
On torrent sites, they provide magnet links. Clicking on torrent magnet link, it opens my systems default torrent client.
In a way, the same with flash and applet.
How do browsers trigger another process and communicate with it? Is there any open standard I am missing?
Ultimately I wish to do video, audio recording with screencast. For screen-recording, Java applet looks like the only solution but applet has its own Issues.
The flash player and applets use plugins, which are native applications to the OS, (i.e. (mostly) not JavaScript), they are not extensions but plugins. For Chrome see chrome://plugins/ to see the list of installed plugins.
For writing a browser plugin, refer to How to write a browser plugin?
The torrent link is totally different, they are done by registering an url protocol to handle. In other words, you say to the computer that, from now on, I will run any urls which have protocol of torrent, i.e.: starts with torrent://. See: Uri Scheme
When the browser sees the uri, it knows that is not handling torrent protocol itself, so it delegates that to OS, which knows what to do with it.
If the browser did know how to handle that, it probably would not delegated that to OS. For example: Google Chrome can handle mailto: links just well without registering mailto protocol to be handled by OS.
You can do this by writing a plugin. It's possible to write plugins that work on most popular browsers, using the same C++ code, using a library called Firebreath
Naturally there is no pre-existing standard plugin that allows the page to start any external application, because that would be a massive security hole and no (sane) user would agree to install such a plugin.
You have to write a specific plugin with capabilities carefully limited to what you need, so the user can agree to let you use just those capabilities. Again, think about how another page might exploit those capabilities before going down this route.

javascript urls in IE pinned site task list

I'm attempting to set up Pinned Site features for my project. The trouble is that I'd like to have the tasks be javascript actions rather than loading a new page. The reason for this is that the site is designed to only ever work in a single window.
I tried adding the following META tag:
<meta name="msapplication-task" content="name=Test Action;
action-uri=javascript:ui('test',8);icon-uri=/img/icons/test.ico" />
However this causes the task to simply not appear. (Using a normal URL makes it show up just fine)
Is there any way to do this? The best I can think of is a hash and check for the hashchange event, but this doesn't work because it gets opened in a new tab of the window...
I'm afraid this is not supported, because action list is designed for launching an application, not for a navigation inside it.
If you really want implement it, you can open a new window, send a message to server via web sockets and let server to forward that message to application window also via web sockets. But this is very hacky approach and works only in IE10.
This issue can be resolved by using a hash. By setting the action-uri to something readable by JavaScript, the JS can then read it, process the instruction, and then clear the hash in preparation for the next task.
This has the advantage that it works even when the window isn't already open, since the JS will read the hash on the first load too.
The catch is to add window-type=self to the content.

Programmatically call a firefox extension from javascript

I have seen this excellent firefox extension, Screengrab!. It takes a "picture" of the web page and copies it to the clipboard or saves it to a png file. I need to do so, but with a new web page, from an url I have in javascript. I can open the web page in a new window, but then I have to call the extension -not to press the control- and saves the page once the page is fully loaded.
Is it possible?
I am pretty certain that it is not possible to access any Firefox add-on through web page content. This could create privacy and/or security issues within the Firefox browser (as the user has never given you permission to access such content on their machine). For this reason, I believe Firefox add-ons run in an entirely different JavaScript context, thereby making this entirely impossible.
However, as Dmitriy's answer states, there are server-side workarounds that can be performed.
Does not look like ScreenGrab has any javascript API.
There is a PHP solution for Saving Web Page as Image.
If you need to do it from JavaScript (from client side) - you can:
Step 1: Create a PHP server app that does the trick (see the link), and that accepts JSONP call.
Step 2: Create a client side page (JavaScript) that will send a JSONP request to that PHP script. See my answer here, that will help you to create such request.

Can JavaScript remove all toolbars, address line and set size of the window?

I would like to run a browser (Internet Explorer) from a command prompt using a specific web address. As a result of that I would like to see a simple IE window without toolbars and address line. I wonder if JavaScript is able to control "parameters" of windows in which it is loaded. I mean, I want to add some JavaScript into my HTML code such that it change the window in which it is loaded.
I do not think this is possible with Javascript (I hope it isn't as it would be a nightmare for web sites to be able to manipulate a browser in this fashion). If it is possible it is more likely that you can use command line arguments in the call to IE (anyone executing processes on the computer should have a higher level of trust than client code delivered as part of a web page). I do not know if such command line arguments exist.
However, you can create a new program that embeds a html renderer and then launch this from the command line. In Windows you can embed an Internet Explorer panel in your program and you will have complete control of what is shown bordering the IE panel.
Another popular choice for embedded HTML rendering is Webkit.
Some links on rendering web pages with c#:
A web browser in c#
WebBrowser class
I think you're looking for window.open(url, '_self', 'location=no,toolbar=no,statusbar=no')
You'll want to put that into a sort of loader or gateway page that loads first and requests the actual content.
Your best bet would be to write a small VBScript file that creats an InternetExplorer.Application object, shows it, sizes it, and navigates it to the target location.
Another alternative would be to create a HTA file (HTML Application) which has no address bar and can be sized as desired.
As another poster notes, web-based script doesn't have permission to do these things.
If you want to run it full screen then you can just run Internet Explorer in Kiosk mode. Just start it like this:
iexplore -k page

Categories

Resources