* Get a script connection, and if there is no script associated with the tab, it injects it. * * @param {string} scriptId * @param {number} tabId * @param {boolean} analysePage Only when the scriptId is 'content', it forces a page analysis before returning the connection. * @returns {Promise<
(scriptId, tabId, injectOnFail=true)
| 92 | * @returns {Promise<Connection>} The connection to the content script |
| 93 | */ |
| 94 | async function getScriptConnection(scriptId, tabId, injectOnFail=true) { |
| 95 | |
| 96 | if (!bgHandler.hasConnectedScript(scriptId, tabId)) { |
| 97 | // Not returning anything if there is no script attached and we don't want to automatically inject the content script |
| 98 | if (!injectOnFail) return undefined; |
| 99 | |
| 100 | await injectScript(tabId); |
| 101 | } |
| 102 | |
| 103 | let conn = await bgHandler.getScriptConnection(scriptId, tabId); |
| 104 | |
| 105 | if (conn) return conn; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Analyzes the page related to a specific tab id and returns a JSON description of the stacking contexts. |
no test coverage detected