Opening a link in a different browser - javascript

I'm trying to find a way to take a link from one browser and open it in another browser. This could be taking a link from a Firefox tab and opening it in Chrome, or taking a link in a Chrome Incognito window and opening it in a non-incognito Chrome window.
Here's some more detail. I have a webpage that refreshes every second, and uses javascript(via Greasemonkey/Tampermonkey) to search for certain keywords. When a keyword in my list matches one associated with a link on the page, it automatically opens that link in a new tab. If it's possible, I need to take those links to a different browser somehow, automatically.
AFAIK, something like this isn't possible with javascript due to security issues. The only two solutions I can think of are:
1: Using AutoHotKey to make a macro to copy the link, alt-tab, and paste into the other program. This is manual, I want something automatic. EDIT: I realized I can use AHK to monitor a page, but I don't know if it could be done without introducing more latency than I would like. Keeping the total time from the webpage refreshing to opening the link as low as possible is the most important thing.
2: Having some other program handle it for me. I'm not aware of any and wonder how difficult/costly it would be to roll my own or have someone make one. I'm not even sure if I could interface it with my current script.
I'm fairly certain it would be possible with number 2, although I don't know about cost or difficulty... could there be another way to accomplish this?
For reference, this is the relevant section of code that I'm currently working with. It opens any link which matches a list of keywords in a new tab. These are the links I'm trying to figure out a way to open in a different browser. It uses dynamic object names and a dynamic URL, but essentially this is just saying if the checkboxes are checked and a link matches my autoOpenList(keyword list), then open the link in a new tab.
if(jQuery.inArray(autoOpenTemp,autoOpenList) != -1 && window['autoAccept' + autoOpenTemp].checked && autoAccept_input.checked ){
var tempURL = LINK_BASE+obj.acc_link;
window.open(tempURL, '_blank');
}

Use Java's HttpServlet Class to create a web application. You can setup the server by Tomcat. Servlets Quick Guide.
Start CLI by Java and open browser through CLI.
Call the web application by url on your page.

Related

How can I delay a new tab from loading with a userscript?

I use a userscript to modify the client-side code of a website. This code is adding an anchor tag to the page. Its target is _blank. The thing is that if I click this link too frequently, the site errors. A simple refresh on the new tab fixes the problem.
When I click on the link and it instantly opens a new tab. But I don't want that new tab to render until I visit it, or with some sort of time delay. Is there a way of achieving this?
I am using Firefox, so Firefox-only solutions are fine. I found this, but I don't see a way of using it to prevent the tab from rendering in the first place. When I Google for this, I see results about add-ons that can solve the problem. But, the links to them always 404. Ideally, the solution would only affect the tabs created by this script instead of the way all tabs work, but if the only way to do it is to affect the way all tabs work, I'd accept that as a solution.
The Tampermonkey documentation says there is a GM_openInTab function. It has a parameter called loadInBackground, but it only decides if the new tab is focused when you click the link.
If there is a way of making this new tab render some HTML of my choosing, I think that would be a neat solution. i.e., I'd write some HTML that, on focus, goes to the actual website's page. If this is an option, I'd need to know how to open a tab to HTML of my choosing in grease monkey.
(Just realization of idea you told in your question yourself)
You can place simple page that waits for focus and then redirects to what you pass in URL parameter somewhere and open in background tabs. Like:
load-url-from-search-on-focus.html?http://example.com:
<!doctype html>
<body
onload="document.title=u=location.search.slice(1)"
onfocus="u?document.location.replace(u):document.write('?search missing')">
Try it.
(data:uri could have been used instead of hosted page, if there weren't those pesky security precautions blocking rendering of top-level datauri navigations :|)

How to change Chrome extensions internal HTML page

I've done some looking around and couldn't find any solution to this problem.
I'm creating a Chrome extension, with a manifest that points to the opening file home-times.html. This works, though I want to redirect it internally to the other page home-welcome.html inside the extension so it loads another page INSIDE the extension.
I've read a lot of questions that refer to changing the current tab's page, though that's not what I am after.
Tests
By using the following code:
test
Opens a new tab, with the extensions page that I am trying to access in that new tab.
If I got you right, you want to change your popup innerHTML, in this case I suggest using jQuery, to change original file to the result you want.
If you just want to open new tab, with your home-welcome.html, you can do this, in your popup.js :
window.open('home-welcome.html','_blank')
If none of this is what you are looking for, can you please provide an example, I will try to help.

Chrome Extensions: How to Manage separate instances of background pages?

Does anyone know of a way to get each separate Chrome Window to run a different background page instance?
Currently, my problem is that I need to open two chrome windows and have each background page be its own separate instance. This "mimics" the act of two separate users using the extension on their own computer. Doing this will allow me to test the extension as two different people yet on one computer. Right now, when I open two Chrome Windows, it uses the one background page instance (as I suppose it should).
I guess any acceptable method would be great, whether that is some form of multiple Chrome sign-ins or installing different instances of chrome. The best solution however would be code based, in the realm of the actual Chrome Extension API, if it allows.
Thanks!
The only way to have two instances of a background page is to enable split incognito behaviour, and open an incognito window (Ctrl + Shift + N).
To enable split incognito mode, add the following to your manifest file:
"split": "incognito"
If you really want to simulate two or more users, use different data directories, by starting Chrome with the --user-data-dir flag. For example:
chromium --user-data-dir=/tmp/whatever/
After some time I solved my problem fairly easily. It requires you to have two Google accounts. So if you do not have two accounts and do not want two accounts, it may be best to use Rob W's answer on this post...
Steps:
Open up a Chrome window.
Click the settings drop down -> then click settings
Under the Users heading, click add new user
You may be prompted to sign in using a Google account, do so
Open up a second window, repeat process and assign the second user to the current window
Now you should have two windows, under two different users. Both use their own settings and their own extensions, along with their own background pages.
Maybe you could instantiate some "background page object" in the one background page for each open window? Put all your functionality in that class and create some array with all the instances in it.
Just some brainstorming, hope it gets you somewhere.

Getting direct URL while clicking javascript button on specific website

I am displaying an online internal website.
Upon clicking on a button "A" it processes a task, and goes to another HTML page. However, this direct address is like "hidden" (hard to explain).
For example, for each page I am accessing by simple button click, it's always the same URL (like http://host.com for every page I display from them).
I am using Firefox, and I need to know how to get the exact HTML address (or direct URL) used for displaying these full new pages. I managed to do it few months ago, but not anymore.
It will help me to automate some tasks and bashing programs. I am openned to any linux browser in case you find a way to help me. Thanks a lot.
it sounds like domain masking is used. you could check the source and see if a frame is being used on the page. the source should indicate the src of the frame, revealing the location of the page.
<frame src="page.html">
If the button uses window.open to navigate to the url, you could override that method and intercept the url there:
var oldOpen = window.open;
window.open = function(){
console.log(arguments[0]);
oldOpen.apply(window, arguments);
};

Get last visited site in another window using Javascript

I am creating a Firefox extension where I need to find out what was the last location visited in another window. Here is an example of what I mean. I present the user with a list of sites from a main interface window. The user clicks on one of the sites and a new window is opened to that site. From there, the user will navigate the site in the new window and will eventually stop browsing or close the window. I need to find out what was the last visited location from that window. Also, the user may be navigating more than one site at a time, so there could be many windows open. I need to know what was the last location for every one of them. So far, the only way that I got it to work is to use a timer and poll the new window every second for document.location.href. There must be a better way.
As far as I know this is not possible in (pure) Javascript due to security/privacy considerations. On the other hand, since you are writing a Firefox plugin you have additional mechanisms you can use.
For instance, you can create a greasemonkey plugin that is applicable to every site. This plugin will record the href using GM_setValue(). The main plugin will read this information via GM_getValue().

Categories