[Solved] Can I open a URL in a popup window? [Linux.]

User Help for Mozilla Firefox
Post Reply
User avatar
sadi
Posts: 23
Joined: April 1st, 2013, 5:14 am
Location: Istanbul

[Solved] Can I open a URL in a popup window? [Linux.]

Post by sadi »

I would like Firefox (Quantum) to open some URLs in a special/popup window, i.e. almost without anything (toolbar, menu bar, tab bar, address bar, etc.) other than the web content.

I think I need a command like this:

Code: Select all

firefox --new-window 'https://web.whatsapp.com/', 'popup', 'width=400,height=600', 'toolbar=0,location=0,menubar=0'
Of course this doesn't work.
Instead I can only obtain a window by clicking a link on a html file with the following underlying code:

Code: Select all

<a href="https://web.whatsapp.com/"
   target="popup"
   onclick="window.open('https://web.whatsapp.com/','popup', 'width=650,height=900');">
   WhatsApp
</a>
I wish I could do this by simply entering a command from terminal - even a standalone script would do (ideally without the address bar, and positioned to the right and not left ;-)

Any suggestions or ideas please?
Last edited by sadi on November 26th, 2017, 2:55 am, edited 2 times in total.
User avatar
Gingerbread Man
Posts: 7735
Joined: January 30th, 2007, 10:55 am

Re: Can I open a URL in a popup window? [Linux.]

Post by Gingerbread Man »

sadi wrote:a special/popup window, i.e. almost without anything (toolbar, menu bar, tab bar, address bar, etc.) other than the web content.
The only thing you can disable are the scrollbars. Everything else is off by default and what isn't (title bar with window controls, location bar and Firefox menu button, resizability) cannot be disabled by websites for security reasons.
sadi wrote:a command from terminal
There's no such command. You could load a local HTML file, which in turn tries to load the pop-up on open. But the pop-up blocker would block it, since it's unrequested. Due to a bug in Firefox, it's not possible to whitelist file:/// URLs in the pop-up blocker. So I don't know what you'd do about that short of disabling the pop-up blocker (bad idea).
Maybe try looking for a third-party program that can open windows without controls (if such a thing exists).
sadi wrote:even a standalone script would do
A script to be run how? :? I don't know what you're trying to accomplish, so I'm not sure what to suggest. But you can save the following as a new bookmark, which would open your pop-up. Just modify the number value of left to what you want.

Code: Select all

javascript:(function(){open('https://web.whatsapp.com/','myWindow','width=650,height=900,top=0,left=1270,scrollbars=no,');})()
User avatar
therube
Posts: 21703
Joined: March 10th, 2004, 9:59 pm
Location: Maryland USA

Re: Can I open a URL in a popup window? [Linux.]

Post by therube »

Bookmarklet, target new windows ?
Fire 750, bring back 250.
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.19) Gecko/20110420 SeaMonkey/2.0.14 Pinball CopyURL+ FetchTextURL FlashGot NoScript
User avatar
sadi
Posts: 23
Joined: April 1st, 2013, 5:14 am
Location: Istanbul

Re: Can I open a URL in a popup window? [Linux.]

Post by sadi »

Gingerbread Man wrote:...you can save the following as a new bookmark, which would open your pop-up. Just modify the number value of left to what you want.

Code: Select all

javascript:(function(){open('https://web.whatsapp.com/','myWindow','width=650,height=900,top=0,left=1270,scrollbars=no,');})()
Thanks a lot. This looks like the closest thing to what I'm trying to achieve.

If I could only get one step closer, i.e. somehow executing this script without first opening an html file that contains it as a link.

Saving it as a new bookmark (which could also mean half way to my goal) doesn't help as it merely adds the url "https://web.whatsapp.com/" to open in a new tab when clicked - unless I'm missing something here.

Probably this two-step solution (saving this javascript in an html file and creating a menu entry /.desktop file with a command like "firefox ~/Documents/WhatsApp.html" and then clicking that link) is the closest I can get to "chromium-browser --app=https://web.whatsapp.com/" ?
User avatar
Gingerbread Man
Posts: 7735
Joined: January 30th, 2007, 10:55 am

Re: Can I open a URL in a popup window? [Linux.]

Post by Gingerbread Man »

Gingerbread Man wrote:Due to a bug in Firefox, it's not possible to whitelist file:/// URLs in the pop-up blocker.
This is now fixed in the latest Nightly. It may have been fixed earlier; try it and see. You should get a "pop-up blocked" toolbar below the location bar. Click the Options button on the right and whitelist the file from there. I can also manually whitelist specific files under Options/Preferences, using forward-slashes instead of backslashes, e.g.

Code: Select all

file:///C:/Desktop/myfile.html
sadi wrote:somehow executing this script without first opening an html file that contains it as a link.
I didn't say make an HTML with a link. I said put the code in a <script> element in an HTML page. No way around it that I can think of, short of creating an add-on for it.
Adding the code as your homepage isn't a solution, unless you disable the pop-up blocker. Unrequested pop-ups that try to open that way can't be whitelisted.
sadi wrote:Saving it as a new bookmark (which could also mean half way to my goal) doesn't help as it merely adds the url "https://web.whatsapp.com/" to open in a new tab when clicked - unless I'm missing something here.
No, it opens in a sized window. If the bookmarklet opens in a tab for you, you probably modified browser.link.open_newwindow or browser.link.open_newwindow.restriction in about:config.
User avatar
sadi
Posts: 23
Joined: April 1st, 2013, 5:14 am
Location: Istanbul

Re: Can I open a URL in a popup window? [Linux.]

Post by sadi »

Gingerbread Man wrote:I didn't say make an HTML with a link. I said put the code in a <script> element in an HTML page.
Thank you! I've got it now (I'm just a beginner in this area).
I've now created an html file named "WhatsApp" with the following contents:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
<title>WhatsApp</title>
</head>
<body>
<script type="text/javascript">
javascript:(function(){open('https://web.whatsapp.com/','myWindow','width=650,height=900,top=0,left=1270');})()
</script>
</body>
</html>
The command "firefox <path>/WhatsApp" now opens a (popup) WhatsApp window (after whitelisting that file only once).
The only remaining flaw in comparison to "cromium-browser --app=https://web.whatsapp.com/" is that this command either opens a blank new tab (if firefox is already running) or a blank window (if firefox is not running) for this blank file.
It's one step ahead of the one with a link to be clicked, but would be perfect if it were possible to automatically close that file after x seconds ( it seems this is no longer possible, so probably I should add the prefix [Solved] thanks to you "Gingerbread Man" ; -)
Gingerbread Man wrote:If the bookmarklet opens in a tab for you, you probably modified browser.link.open_newwindow or browser.link.open_newwindow.restriction in about:config.
I checked, although I didn't make any such modification: they are both in default condition, i.e. integer 3 and 2 respectively. But I'm not very much interested in this path anyway.

Thanks again for helping me make a considerable progress :-)

Firefox Quantum 57.01 (64-bit)
User avatar
Gingerbread Man
Posts: 7735
Joined: January 30th, 2007, 10:55 am

Re: [Solved] Can I open a URL in a popup window? [Linux.]

Post by Gingerbread Man »

Oh, no. Don't put javascript: inside a <script> element; that's just for the bookmarklet. You don't need the anonymous function either.

Scripts can only close windows that they opened, so that's not an option. The best workaround I can think of is to first set browser.link.open_newwindow.override.external to 1 in about:config so that links from other programs open in the current tab. This isn't necessary if you've set browser.link.open_newwindow to 1. Then have the script navigate back to the previous page:

Code: Select all

<!DOCTYPE html>

<html lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>WhatsApp pop-up opener</title>
<script type="text/javascript">
window.open('https://web.whatsapp.com/','myWindow','width=650,height=900,top=0,left=1270');
history.back();
</script>
</head>
<body>
</body>
</html>
You're welcome.
User avatar
sadi
Posts: 23
Joined: April 1st, 2013, 5:14 am
Location: Istanbul

Re: [Solved] Can I open a URL in a popup window? [Linux.]

Post by sadi »

Gingerbread Man wrote:Oh, no. Don't put javascript: inside a <script> element; that's just for the bookmarklet.
Wov! This effectively closes the blank tab created when firefox is running! 8-)
And now I've got the bookmark working as well (after finally understanding what you have actually suggested) :)
User avatar
Gingerbread Man
Posts: 7735
Joined: January 30th, 2007, 10:55 am

Re: Can I open a URL in a popup window? [Linux.]

Post by Gingerbread Man »

Gingerbread Man wrote:The only thing you can disable are the scrollbars. Everything else is off by default and what isn't (title bar with window controls, location bar and Firefox menu button, resizability) cannot be disabled by websites for security reasons.
Come to think of it, if you don't ever open the site in regular tabs, you can hide the navigation toolbar for it with userChrome.css. Replace the text between quotation marks with the beginning of the web page title.

Code: Select all

#main-window[title^="Web page title before the - Mozilla Firefox part"] #nav-bar { visibility: collapse !important; }
Unfortunately the width/height and screenX/screenY attributes don't provide accurate information, so I don't see how to restrict the style to the pop-up window only.
User avatar
sadi
Posts: 23
Joined: April 1st, 2013, 5:14 am
Location: Istanbul

Re: Can I open a URL in a popup window? [Linux.]

Post by sadi »

Gingerbread Man wrote: Come to think of it, if you don't ever open the site in regular tabs, you can hide the navigation toolbar for it with userChrome.css.
Wov! No more useless address bar in this special WhatsApp window!
That brings us closer to perfection in creating a virtual whatsapp desktop client without duplicating a web browser program ;-)

To summarize:

1) Set browser.link.open_newwindow.override.external to 1 in about:config so that links from other programs open in the current tab (or set browser.link.open_newwindow to 1, if you wish).

2) Make sure you have "/chrome/userChrome.css" under your mozila profile directory, and it includes this line:

Code: Select all

#main-window[title^="WhatsApp"] #nav-bar { visibility: collapse !important; }
3) Tell Firefox to open this html file, e.g. named "WhatsApp":

Code: Select all

<!DOCTYPE html>
<html lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>whatsapp popup window launcher</title>
<script type="text/javascript">
window.open('https://web.whatsapp.com/','myWindow','width=670,height=900,top=0,left=1250');
history.back();
</script>
</head>
<body>
</body>
</html>
This solution avoids leaving an empty firefox window tab in step 3 if there is a firefox window already open, but it seems there is no way of avoiding it if this is the first time a firefox window is opened by the user.
But another, perhaps more important, inevitable flaw is that if you have only this WhatsApp window open, and if you click a web link in say a Thunderbird window, unfortunately it will open in that WhatsApp window.
So it may be better to skip step 1, and get used to leaving a blank new tab in step 3 and simply close it manually...
User avatar
Gingerbread Man
Posts: 7735
Joined: January 30th, 2007, 10:55 am

Re: Can I open a URL in a popup window? [Linux.]

Post by Gingerbread Man »

sadi wrote:So it may be better to skip step 1, and get used to leaving a blank new tab in step 3 and simply close it manually...
Like I said, you can either have the script navigate away to another page after opening the pop-up, or open external links in the most recent tab in the most recent window, then navigate back to the previous page.

If neither of those will do, you can launch the HTML page via an automation utility that will also close the tab for you. The following AutoHotkey script works on Windows. I'm not sure what you'd use on Linux, maybe something like Actiona; all the other alternatives I've seen weren't updated in 5 years or more.

Code: Select all

Run, firefox.exe C:\Users\Gingerbread Man\Desktop\popup.html ; launch the HTML page
WinWait, Pop-up opener - Nightly, , 20 ; wait 20s for Firefox to start
if ErrorLevel ; alert in case it doesn't start
{
    MsgBox, WinWait timed out.
    return
}
else
    Sleep, 1250 ; wait 1.25s for the pop-up to open
    ControlSend, ahk_parent, ^w, Pop-up opener - Nightly ; close the HTML page tab
    return ; exit
User avatar
sadi
Posts: 23
Joined: April 1st, 2013, 5:14 am
Location: Istanbul

Re: Can I open a URL in a popup window? [Linux.]

Post by sadi »

Gingerbread Man wrote: If neither of those will do, you can launch the HTML page via an automation utility that will also close the tab for you.
Oh, thanks for the tip!
How did I forget that?!
It's much simpler to close a particular window under Linux of course ;-)

Finally, here is a 100% perfect solution:

1) Make sure that you have "/chrome/userChrome.css" under your user mozilla firefox profile directory, and that it includes this line:

Code: Select all

#main-window[title^="WhatsApp"] #nav-bar { visibility: collapse !important; }
2) Create an html file (e.g. named "WhatsAppWeb") with the following contents:

Code: Select all

<!DOCTYPE html>
<html lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>WhatsApp Web Launcher</title>
<script type="text/javascript">
window.open('https://web.whatsapp.com/','myWindow','width=670,height=900,top=0,left=1250');
</script>
</head>
<body>
</body>
</html>
3) Enter the command

Code: Select all

firefox -new-window "/<path>/WhatsAppWeb"
from terminal and allow it to open popup window from now on by saving this preference, and then close firefox window(s).

4) Finally, whenever you want to start WhatsApp Web, run these commands - e.g. from terminal or a .desktop file, via bash script, etc.:

Code: Select all

firefox -new-window "/<path>/WhatsAppWeb" &
sleep 5s
wmctrl -ic "$(wmctrl -lp | grep "$(pgrep firefox)" | grep -v 'WhatsApp - Mozilla Firefox' | tail -1 | awk '{ print $1 }')"
Note: In this last step, WhatsApp Web popup window is launched from a new blank Firefox window, and then that blank window is closed after 5 seconds (which might need to be adjusted according to different conditions), thereby effectively opening a special Firefox window for WhatsApp Web only - nothing more, nothing less :-)
Post Reply