Can't window.open() a XUL window from a menu

Talk about code development, features, specific bugzilla bugs, enhancements, patches, and other highly technical things.

Moderator: satrow

Forum rules
Please keep everything here strictly on-topic.
This board is meant for Pale Moon source code development related subjects only like code snippets, patches, specific referenced Bugzilla bugs, mercurial, etc.

This is not for tech support! Please do not post tech support questions in the "Development" board!
Please make sure not to use this board for support questions. Most "bug reports" do not belong in this board and should initially be posted in Community Support or other relevant support boards.

Please keep things on-topic as this forum will be used for reference for Pale Moon development. Expect topics that aren't relevant as such to be moved or deleted.
Post Reply
User avatar
moonbat
Board Warrior
Board Warrior
Posts: 1072
Joined: 2015-12-09, 15:45
Location: Australia

Can't window.open() a XUL window from a menu

Post by moonbat » 2019-09-29, 10:06

I'm trying to make an overlay extension to display a Youtube video in a pop up window, similar to the buggy 'Youtube Video Player Pop Out' from CAA (which incidentally is targeted at PaleMoon). That one is a Jetpack extension and creates its entire UI in bootstrap.js. It doesn't let you drag the generated Javascript window smoothly, and sometimes the window might vanish while dragging if the video is playing (to get it back, you have to launch another window from a Youtube page).

I've created a new menu item in the Tools menu like so:

Code: Select all

<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin/"?>
<overlay id="pmplayer-browser-overlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
	<script type="application/x-javascript" src="chrome://pmplayer/content/youtubeplayer.js"/>
	<menupopup id="menu_ToolsPopup">
		<menu id="pmplayer-menu" label="PMPlayer">
			<menuitem id="pmplayer-play" label="Play" oncommand="PMPlayer.Youtube.openWindow();"></menuitem>
		</menu>
	</menupopup>
</overlay>
and the event handler looks like this -

Code: Select all

    playerWindow:null,
    openWindow :function (){
    		console.log("Inside openWindow");
            //if (playerWindow==null){
		playerWindow = window.open('chrome://pmplayer/content/window-youtube.xul','pmplayer-yt','chrome,width=640,height=480');
		window.alert("hi");
	    //}
    }
    
Clicking the menu item does nothing, and nothing is shown in the browser console either :(

If relevant, this is my chrome.manifest -

Code: Select all

content	pmplayer							  				content/
skin	pmplayer							  classic/1.0	skin/
locale	pmplayer							  en-US			locale/en-US/

overlay chrome://browser/content/browser.xul  chrome://pmplayer/content/browserOverlay.xul
Last edited by moonbat on 2019-09-29, 12:14, edited 1 time in total.
"One hosts to look them up, one DNS to find them and in the darkness BIND them."

Linux Mint 19.3 Xfce x64 on HP i5 laptop with 4 GB RAM, always latest versions of PM & Basilisk unless specified.

vannilla
Keeps coming back
Keeps coming back
Posts: 812
Joined: 2018-05-05, 13:29

Re: Can't window.open() a XUL window from a menu

Post by vannilla » 2019-09-29, 11:06

I also made something that opens a window from the menu (it was my first extension, too.)
Maybe you can compare it with yours.
At first glance the difference seems to be that you are setting as the script's source a chrome URL while I simply give the script name.
What happens if you try to log something instead of opening a window?

User avatar
moonbat
Board Warrior
Board Warrior
Posts: 1072
Joined: 2015-12-09, 15:45
Location: Australia

Re: Can't window.open() a XUL window from a menu

Post by moonbat » 2019-09-29, 12:09

vannilla wrote:
2019-09-29, 11:06
I also made something that opens a window from the menu (it was my first extension, too.)
Maybe you can compare it with yours.
At first glance the difference seems to be that you are setting as the script's source a chrome URL while I simply give the script name.
What happens if you try to log something instead of opening a window?
I changed the src to just the script name, like in your code and added console log message in the handler, but absolutely nothing happens :(
It's like it never registered the handler. I am following the XUL tutorial and reference, and really can't figure what I'm doing wrong.
Testing on a separate profile with no other extensions.
"One hosts to look them up, one DNS to find them and in the darkness BIND them."

Linux Mint 19.3 Xfce x64 on HP i5 laptop with 4 GB RAM, always latest versions of PM & Basilisk unless specified.

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 25675
Joined: 2011-08-28, 17:27
Location: 58°2'16"N 14°58'31"E
Contact:

Re: Can't window.open() a XUL window from a menu

Post by Moonchild » 2019-09-29, 12:09

Seems like a logical error here:

Code: Select all

    playerWindow:null,
    openWindow :function (){
            if (playerWindow!=null){
		playerWindow = window.open('chrome://pmplayer/content/window-youtube.xul','pmplayer-yt','chrome,width=640,height=480');
	    }
    }
    
You set playerwindow to null. then check if it's not null, and open a window if so, which will never happen.
I'm assuming you want to check if it exists to not open more than one window? You want to check playerWindow == null then, not !=, or simply if (!playerWindow) {
"There will be times when the position you advocate, no matter how well framed and supported, will not be accepted by the public simply because you are who you are." -- Merrill Rose
Image

User avatar
moonbat
Board Warrior
Board Warrior
Posts: 1072
Joined: 2015-12-09, 15:45
Location: Australia

Re: Can't window.open() a XUL window from a menu

Post by moonbat » 2019-09-29, 12:11

Moonchild wrote:
2019-09-29, 12:09

You set playerwindow to null. then check if it's not null, and open a window if so, which will never happen.
I'm assuming you want to check if it exists to not open more than one window? You want to check playerWindow == null then, not !=, or simply if (!playerWindow) {
I realized the problem after submitting the post, but with that if block removed and just a window.open, or a console.log, nothing happens and nothing shows up in the console. Browser console, I'm assuming.
"One hosts to look them up, one DNS to find them and in the darkness BIND them."

Linux Mint 19.3 Xfce x64 on HP i5 laptop with 4 GB RAM, always latest versions of PM & Basilisk unless specified.

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 25675
Joined: 2011-08-28, 17:27
Location: 58°2'16"N 14°58'31"E
Contact:

Re: Can't window.open() a XUL window from a menu

Post by Moonchild » 2019-09-29, 12:15

Another thing you want to be VERY careful with. I'm assuming you are going to open YT content in that chrome window? DON'T. Never load untrusted content in a chrome window because chrome windows have chrome privileges (= application level privileges, which is in most cases system-level).

Also, you have to make sure window-youtube.xul exists in the specified path or window.open() will do nothing.
"There will be times when the position you advocate, no matter how well framed and supported, will not be accepted by the public simply because you are who you are." -- Merrill Rose
Image

User avatar
moonbat
Board Warrior
Board Warrior
Posts: 1072
Joined: 2015-12-09, 15:45
Location: Australia

Re: Can't window.open() a XUL window from a menu

Post by moonbat » 2019-09-29, 12:36

Moonchild wrote:
2019-09-29, 12:15
Another thing you want to be VERY careful with. I'm assuming you are going to open YT content in that chrome window? DON'T. Never load untrusted content in a chrome window because chrome windows have chrome privileges (= application level privileges, which is in most cases system-level).
I figured this would be a concern and am using an iframe, with the Youtube Iframe API. As per the documentation for iframe, you can set the attribute 'type' to 'content' and that will prevent it from accessing the enclosing chrome.
I assume this is the accepted practice, since the only existing extension is a bootstrap one that uses a window created out of javascript for displaying the youtube video.
Moonchild wrote:
2019-09-29, 12:15
Also, you have to make sure window-youtube.xul exists in the specified path or window.open() will do nothing.
The path is correct, don't know why it doesn't even show a console log or alert. Seems like the event handler isn't getting called at all.
"One hosts to look them up, one DNS to find them and in the darkness BIND them."

Linux Mint 19.3 Xfce x64 on HP i5 laptop with 4 GB RAM, always latest versions of PM & Basilisk unless specified.

vannilla
Keeps coming back
Keeps coming back
Posts: 812
Joined: 2018-05-05, 13:29

Re: Can't window.open() a XUL window from a menu

Post by vannilla » 2019-09-29, 12:37

I tried executing the example and it doesn't work for me either.
I even tried to open an alert message with nsIPrompService, but nothing happens.


Found the culprit.
Change the following:

Code: Select all

<menupopup id="menu_ToolsPopup">
	<menu id="pmplayer-menu" label="PMPlayer">
		<menuitem id="pmplayer-play" label="Play" oncommand="PMPlayer.Youtube.openWindow();"></menuitem>
	</menu>
</menupopup>
into this:

Code: Select all

<menupopup id="menu_ToolsPopup">
	<menu id="pmplayer-menu" label="PMPlayer">
		<menupopup id="pmplayer-submenu">
			<menuitem id="pmplayer-play" label="Play" oncommand="PMPlayer.Youtube.openWindow();"></menuitem>
		</menupopup>
	</menu>
</menupopup>
If you don't plan to have more entries than "Play", then you can just place the "pmplayer-play" item directly inside the "menu_ToolsPopup" menu.

User avatar
moonbat
Board Warrior
Board Warrior
Posts: 1072
Joined: 2015-12-09, 15:45
Location: Australia

Re: Can't window.open() a XUL window from a menu

Post by moonbat » 2019-09-29, 12:56

vannilla wrote:
2019-09-29, 12:37
I tried executing the example and it doesn't work for me either.
I even tried to open an alert message with nsIPrompService, but nothing happens.
You mean my code snippet, or some other example?
"One hosts to look them up, one DNS to find them and in the darkness BIND them."

Linux Mint 19.3 Xfce x64 on HP i5 laptop with 4 GB RAM, always latest versions of PM & Basilisk unless specified.

vannilla
Keeps coming back
Keeps coming back
Posts: 812
Joined: 2018-05-05, 13:29

Re: Can't window.open() a XUL window from a menu

Post by vannilla » 2019-09-29, 18:18

I updated my previous post, please check if it works.

User avatar
moonbat
Board Warrior
Board Warrior
Posts: 1072
Joined: 2015-12-09, 15:45
Location: Australia

Re: Can't window.open() a XUL window from a menu

Post by moonbat » 2019-09-30, 01:38

Thanks. Was troubleshooting with Tobin last night and he pointed this out. On to the next challenge!
"One hosts to look them up, one DNS to find them and in the darkness BIND them."

Linux Mint 19.3 Xfce x64 on HP i5 laptop with 4 GB RAM, always latest versions of PM & Basilisk unless specified.

Post Reply