Index: gc_lang/fr/webext/content_scripts/api.js ================================================================== --- gc_lang/fr/webext/content_scripts/api.js +++ gc_lang/fr/webext/content_scripts/api.js @@ -85,5 +85,11 @@ } else { console.log("[Grammalecte API] Error: one or several parameters aren’t string."); } } } + +/* + Tell to the webpage that the Grammalecte API is ready. +*/ +document.dispatchEvent(new Event('GrammalecteLoaded')); + Index: gc_lang/fr/webext/content_scripts/init.js ================================================================== --- gc_lang/fr/webext/content_scripts/init.js +++ gc_lang/fr/webext/content_scripts/init.js @@ -518,18 +518,15 @@ /* Callable API for the webpage. - The API script must be injected this way to be callable by the page -*/ -let xScriptGrammalecteAPI = document.createElement("script"); -xScriptGrammalecteAPI.src = browser.extension.getURL("content_scripts/api.js"); -document.documentElement.appendChild(xScriptGrammalecteAPI); +*/ document.addEventListener("GrammalecteCall", function (xEvent) { // GrammalecteCall events are dispatched by functions in the API script + // The script is loaded below. try { let oCommand = xEvent.detail; switch (oCommand.sCommand) { case "openPanelForNode": if (oCommand.xNode) { @@ -565,12 +562,17 @@ } catch (e) { showError(e); } }); + +// The API script must be injected this way to be callable by the page +let xScriptGrammalecteAPI = document.createElement("script"); +xScriptGrammalecteAPI.src = browser.extension.getURL("content_scripts/api.js"); +document.documentElement.appendChild(xScriptGrammalecteAPI); /* Note: Initialization starts when the background is connected. See: oGrammalecteBackgroundPort.listen() -> case "init" */