fx-autoconfig
fx-autoconfig copied to clipboard
Proper method of injecting JavaScript and CSS into content
To explain my use case, I want to create a table of contents on the right in the about:preferences
.
- https://tscanlin.github.io/tocbot/
To do this, I have to inject JavaScript and CSS into the about:preferences
page.
I think it's possible with AutoConfig, but I don't know the right way.
(I hope there is no effect on browser.xhtml
)
It may also be associated with #33
Accessing content documents in general is very tricky and something I try to stay away from.
But if the content document you are trying to access is in the parent process (like about:preferences and about:addons) then you can access them trivially - just include their address in the script header:
// ==UserScript==
// @include about:preferences
// ==/UserScript==
console.log(document.location.href)
This script should only be executed in about:preferences
- not the main window which is the default.
Note that scripts are evaluated during DOMContentLoaded
event, so chances are that the page has not yet been fully constructed at that point.
Oh thank you. I'll try and share the code if I can!!