I'm trying to build a Chrome Extension to add a personalized signature/message to the end of a message/comment in Trix
From the reading of the docs and other similar issues I've found it seems pretty straightforward. Something like this from my content.js
file...
'use strict'
var sig = '<p>Testing 1,2</p>';
//chrome.storage.sync.get(null, function (data) {
// sig = data.signature;
//});
document.addEventListener("trix-initialize", function (event) {
event.target.editor.loadHTML(sig);
});
...should do the trick. But I keep getting this error...
Uncaught TypeError: Cannot read property 'loadHTML' of undefined at HTMLDocument.<anonymous>
I've included my manifest, script, and content files here after getting a bit more guidance
manifest.json
{
"manifest_version": 2,
"name": "BaseCamp Signature",
"description": "This extension adds signature to Basecamp",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html",
"default_title": "Title!"
},
"permissions": [
"storage",
"activeTab",
"tabs",
"https://3.basecamp.com/*"
],
"content_scripts": [
{
"matches": ["https://3.basecamp.com/*/*"],
"all_frames": true,
"js": ["content.js"],
"run_at": "document_end"
}
],
"web_accessible_resources": [
"script.js",
]
}
script.js
'use strict'
var sig = '<p>Testing 1,2</p>';
//chrome.storage.sync.get(null, function (data) {
// sig = data.signature;
//});
document.addEventListener("trix-initialize", function (event) {
event.target.editor.loadHTML(sig);
});
content.js
var s = document.createElement('script');
// TODO: add "script.js" to web_accessible_resources in manifest.json
s.src = chrome.extension.getURL('script.js');
s.onload = function() {
this.remove();
};
(document.head || document.documentElement).appendChild(s);