extension behaving differently on linux and windows

Add-ons for Pale Moon and other applications
General discussion, compatibility, contributed extensions, themes, plugins, and more.

Moderators: FranklinDM, Lootyhoof

thosrtanner
Lunatic
Lunatic
Posts: 395
Joined: 2014-05-10, 18:19
Location: UK

extension behaving differently on linux and windows

Unread post by thosrtanner » 2023-05-29, 08:44

Operating system: Linux NixOS
Browser version: 32.2.0
32-bit or 64-bit browser?: 64 bit (AVX build)
Problem URL: https://github.com/ThosRTanner/inforss/ ... sOption.js
Browser theme (if not default):
Installed add-ons: n/a
Installed plugins: (about:plugins): none (or at least all but inforss disabled)

If possible, please include the output of help->troubleshooting information (as text):
Not available
Entered because someone is having problems with an extension I maintain.

The code in the URL above is called when clicking the option button in about:addons or right clicking the menu icon.

On windows, it works fine.

On the above mentioned linux, the user gets this trace in the console:

Code: Select all

console.error: 
  Exception in init@chrome://inforss/content/inforssOption.js:89:13
  Message: ReferenceError: can't access lexical declaration `WindowMediator' before initialization
  Stack:
    init@chrome://inforss/content/inforssOption.js:73:11
onload@chrome://inforss/content/inforssOption.xul:1:1
and there's no information in the options window.

I'm at a bit of a loss as to why this should be happening on linux and how to get round it (not to mention how to test it...)

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

Re: extension behaving differently on linux and windows

Unread post by moonbat » 2023-05-29, 08:58

Can't see the code but instead of the older way of calling nsIWindowMediator you can import Services.jsm and use Services.wm for any WindowMediator API calls.
"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: 35402
Joined: 2011-08-28, 17:27
Location: Motala, SE
Contact:

Re: extension behaving differently on linux and windows

Unread post by Moonchild » 2023-05-29, 13:39

On Windows, the interface is almost certainly being called by the browser code itself for various windowing functions. On Linux, that may not necessarily be true because of using GTK.
the Services module route is usually easier, because it will handle initialization if necessary. Otherwise, you have to add an initializer line before using interfaces instead of relying on a browser-initialized state.
"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

thosrtanner
Lunatic
Lunatic
Posts: 395
Joined: 2014-05-10, 18:19
Location: UK

Re: extension behaving differently on linux and windows

Unread post by thosrtanner » 2023-05-29, 16:30

Thanks. will try that and see if it fixes the users problem

thosrtanner
Lunatic
Lunatic
Posts: 395
Joined: 2014-05-10, 18:19
Location: UK

Re: extension behaving differently on linux and windows

Unread post by thosrtanner » 2023-05-29, 16:44

Now it says

console.error:
Exception in init@chrome://inforss/content/inforssOption.js:93:13
Message: ReferenceError: can't access lexical declaration `Services' before initialization
Stack:
init@chrome://inforss/content/inforssOption.js:77:11
onload@chrome://inforss/content/inforssOption.xul:1:1


the code now starts off like this:

Code: Select all

const inforss = {};

Components.utils.import("chrome://inforss/content/modules/inforss_Debug.jsm",
                        inforss);

Components.utils.import(
  "chrome://inforss/content/windows/inforss_Options.jsm",
  inforss
);

//const WindowMediator = Components.classes[
//  "@mozilla.org/appshell/window-mediator;1"].getService(
//  Components.interfaces.nsIWindowMediator);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");

function init()
{
  "use strict";
  try
  {
    // We go through this rigmarole so that when generating the status line for
    // a feed we can get hold of the current status. Mediator.find_feed exists
    // purely for this and we have to make it a global variable in the main
    // code.
    let mediator = null;
    const enumerator = Services.wm.getEnumerator(null);

Line 77 is the one that is getting the error

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

Re: extension behaving differently on linux and windows

Unread post by Moonchild » 2023-05-29, 16:52

Not sure what ChromeUtils is or is used for or why you're trying to const assign it, but the normal way to get Services is using Components.utils (Cu) and importing it as-is

Code: Select all

Components.utils.import("resource://gre/modules/Services.jsm");
"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

thosrtanner
Lunatic
Lunatic
Posts: 395
Joined: 2014-05-10, 18:19
Location: UK

Re: extension behaving differently on linux and windows

Unread post by thosrtanner » 2023-05-29, 16:54

I was using the code from the link moonbat posted

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

Re: extension behaving differently on linux and windows

Unread post by vannilla » 2023-05-29, 17:15

Oh, yeah, this thing about the Services.jsm documentation page was something I noticed some time ago but then forgot about.

Basically a number of pages were already changed from the "standard XPCOM" to the transitional technology that eventually became WebExtensions, i.e. the bootstrapping abomination from the Australis era, before it was scraped to become UDN.

I don't remember which pages are affected and anyway there are probably more than what I discovered.

@thorstanner
With the above being said, the least-prone-to-breakage way to import any JSM file in an extension is by using Components.utils.import as-is without assigning any variable.

thosrtanner
Lunatic
Lunatic
Posts: 395
Joined: 2014-05-10, 18:19
Location: UK

Re: extension behaving differently on linux and windows

Unread post by thosrtanner » 2023-05-29, 17:44

Doesn't seem to want to work at the top level at all.

Replaced the

Code: Select all

const { Services } 
with a straight

Code: Select all

Components.utils.import("resource://gre/modules/Services.jsm");
and got

Code: Select all

console.error: 
  Exception in init@chrome://inforss/content/inforssOption.js:98:13
  Message: ReferenceError: Services is not defined
  Stack:
    init@chrome://inforss/content/inforssOption.js:82:11
onload@chrome://inforss/content/inforssOption.xul:1:1

thosrtanner
Lunatic
Lunatic
Posts: 395
Joined: 2014-05-10, 18:19
Location: UK

Re: extension behaving differently on linux and windows

Unread post by thosrtanner » 2023-05-29, 20:09

Well, I got this to work by putting everything inside the init function, which seems a bit unintuitive. But at least it works.

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

Re: extension behaving differently on linux and windows

Unread post by vannilla » 2023-05-29, 20:28

Normally it shouldn't need that, but I don't know enough about the code to know what's up.

thosrtanner
Lunatic
Lunatic
Posts: 395
Joined: 2014-05-10, 18:19
Location: UK

Re: extension behaving differently on linux and windows

Unread post by thosrtanner » 2023-05-29, 20:41

it's the js attached to a window with

Code: Select all

<script type="application/x-javascript" src="chrome://inforss/content/inforssOption.js"/>
- link is somewhere at the start of this thread.

It didn't like any of my imports. Once it had got past that bit, and called the rest of the code, all the importing worked fine. Apart from the one where I'd used names in different cases, which works fine on windows but not so fine on linux.

Locked