Attach script to webpage (inb4 'use Greasemonkey')

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: 4983
Joined: 2015-12-09, 15:45

Attach script to webpage (inb4 'use Greasemonkey')

Unread post by moonbat » 2020-04-19, 14:03

I'm converting Pure URL from a bootstrap (not made by me) to an overlay extension. It cleans up garbage tracking parameters at 2 places - when URL requests are made, and also by cleaning up links on webpages. The first part uses an HTTP observer to fix outgoing links, the second part injects a static script using the Addon SDK's page-mod mechanism.

I was able to get the first part working by implementing an observer listener and calling the same function that processes regex on URLs. For the second part, there seems to be no direct equivalent in the overlay/XUL/XPCOM API.

I've been trying to use mozIJSSubScriptLoader detailed here in conjunction with attaching a script on page load or a listener on gBrowser, but no dice.

Is there another way to get a script to run on a webpage directly? This script in question is a large, complex one loaded from a chrome URL, so there's no fear of remote manipulation or anything like it, and the extension has worked flawlessly so far.
"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