Can I detect a redirection happening in a browser, which is not pointed to HTTP(s) protocol?
For example, my script redirects to something like ftp://, sms://, ws:// using
location.href=ws://abc/a
Is there a way to detect such redirection using JS? If useful, I can involve chrome ext environment in this as well.
Though this is not straight away, if you are using chrome extension, you can rely on chrome.webRequest.onHeadersReceived.* API which would give some clue via responseHeaders and you can detect the non-http redirects and setup actions accordingly.
Related
I am creating a Google Chrome extension (and possible support for Firefox and Safari) that displays a brief summary of the page the user is reading. The extension detects the url from the browser's tab, sends it to the backend app server, which creates a summary and returns the response back. There's some more backend machine learning analysis that is being done on the content (hence the need for backend app server).
During my local testing, I found that my extension is showing summaries for pages which are also behind paywalls e.g. NYTimes. I want to respect the paywalls. So my question is, is there a way for my extension to detect if the url is behind a paywall - and then respect it? I believe this can be achieved through the use of cookies - but I'm not entirely sure how to have a generalized solution.
I have an application which needs to be installed on windows machine which uses a custom protocol like "myapp://". So i have a button on a web page which when clicked opens that application.
When i click the button, i need to check whether that protocol is supported by the browser or not, if yes, open the application, if no, show an error.
There are several hacks available on the internet and I tried a few but didn't seem to work. I want to do this in a cleaner way. Can anyone please help?
No can do. The browser is specifically blocked from that level of access. You can't even read a file directly from their system unless the user gives it to you via a file input.
In theory, you could write your application in such a way that it reports back to your server when it's installed but that doesn't guarantee that it was installed on that machine.
Is it possible to open a link in another browser using Javascript?
I basically want to open Firefox from Google Chrome. I'm (attempting to) write an extension for chrome, but I can't find anything pointing to be able to do this.
I think I could use NPAPI plugins for Chrome, but they are being deprecated and are very insecure, so are there any alternate options?
You did not provide enough info so I can't asses the utility of what I'm about to offer, but here's an option:
Basically, use URL schemes to launch your application of choice from the browser. Start reading this SO question - How do I register a custom URL protocol in Windows?. You'll need to register some prefix - like "firefox://" for it to work. Should also be possible on other platforms.
Of course, this assumes that your user has firefox installed and that you can register on their machine. If this application is meant for a the general public, you'll need to perform those by some other means (installer?)
Yet another way to go is (as mentioned above) to run some native code via the extension. Not a simple choice: once again you need to somehow install the native code on the host machine (and you cannot do that via Chrome extensions, for security reasons).
You can use Native Messaging, paired with a native program which will launch the browser. I would write the native application in something like Python.
I'm trying to create a web page that can connect to a client-local WebSocket server. The idea is to use the JavaScript client running in the browser as kind of a proxy to enable communication between the remote web server and the locally installed client application which implements the WebSocket service.
So basially, what I'd do is load a web page from https://example.com which includes some JavaScript that opens a new WebSocket to ws://localhost:1234/context.
This works fine as long as the web page is accessed via http. As soon as https is used, however, Firefox and Internet Explorer refuse to connect and the WebSocket constructor throws an exception (SecurityError, code 18).
Now, I already found advice from Mozilla stating that https sites should only use secure (wss://) WebSockets and plain http sites should only use plain WebSockets (link). But I don't really see the security issue when connecting to localhost from within an https context. Besides, this works like a charm for Chrome, Opera and Safari.
So the actual question is: Is there any way to work around this issue? Like introducing a non-https context inside the web page or something similar to get all browsers to connect to ws://localhost from within a https-delivered web page?
Thanks a lot in advance! I'm not exactly a web developer so this kind of browser-specific behaviour isn't really in my fields of expertise :)
You have to accept the cert first.
You can do this by simply going to https://localhost:1234/context, in your case. Once that's done, you can use the wss URL in your question.
I'd like a local process on my machine to be able to trigger javascript in a specific tab in my local Google Chrome browser. The tab is not connecting to localhost, but to another known domain.
This may sound a bit weird, but what I'm actually trying to do is allow my in-browser music player to be controlled via global OS keyboard shortcuts, so I don't have to go to my tab in Chrome to pause or skip a track, for example.
I haven't been able to find any references to this type of behavior anywhere. Here are some solutions I've though of so far:
I tried looking at the Chrome Extensions APIs, and found the NPAPI Plugins which seem to allow javascript to trigger an external process, but I'm not sure if I could get it to work in the opposite way?
If directly triggering javascript is not possible, I may look into opening an HTML5 WebSocket to a tiny localhost webserver that can push control messages to the browser. I've read that WebSockets can function cross-domain in this way.
If both of the above don't work, I could always have a localhost process push to the remote server, which can forward the message back to my Chrome tab via WebSockets or another callback method. I really hope I can avoid this.
Are there features of Chrome extensions I'm overlooking that can be triggered externally? Or will a NPAPI plugin be able to do what I want? Or is there a better solution for this somehow? These all seem a little needlessly complex for such a simple task.
I would use the NPAPI Plugin becasue it is the best one too use for the thing your doing.
Good luck completing it.