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

Talk about code development, features, specific bugs, enhancements, patches, and similar things.
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 bugs, git, the repositories, 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. Please post issues with specific websites, extensions, etc. in the relevant boards for those topics.

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.
User avatar
moonbat
Knows the dark side
Knows the dark side
Posts: 4981
Joined: 2015-12-09, 15:45
Contact:

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

Unread 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."

Image
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX

vannilla
Moon Magic practitioner
Moon Magic practitioner
Posts: 2193
Joined: 2018-05-05, 13:29

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

Unread 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
Knows the dark side
Knows the dark side
Posts: 4981
Joined: 2015-12-09, 15:45
Contact:

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

Unread 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."

Image
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35620
Joined: 2011-08-28, 17:27
Location: Motala, SE
Contact:

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

Unread 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) {
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

User avatar
moonbat
Knows the dark side
Knows the dark side
Posts: 4981
Joined: 2015-12-09, 15:45
Contact:

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

Unread 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."

Image
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35620
Joined: 2011-08-28, 17:27
Location: Motala, SE
Contact:

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

Unread 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.
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

User avatar
moonbat
Knows the dark side
Knows the dark side
Posts: 4981
Joined: 2015-12-09, 15:45
Contact:

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

Unread 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."

Image
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX

vannilla
Moon Magic practitioner
Moon Magic practitioner
Posts: 2193
Joined: 2018-05-05, 13:29

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

Unread 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
Knows the dark side
Knows the dark side
Posts: 4981
Joined: 2015-12-09, 15:45
Contact:

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

Unread 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."

Image
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX

vannilla
Moon Magic practitioner
Moon Magic practitioner
Posts: 2193
Joined: 2018-05-05, 13:29

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

Unread post by vannilla » 2019-09-29, 18:18

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

User avatar
moonbat
Knows the dark side
Knows the dark side
Posts: 4981
Joined: 2015-12-09, 15:45
Contact:

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

Unread 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."

Image
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX

Locked