/
githubmirror
/
obsidian-clipper
Обзор
Документация
Войти
/
githubmirror
/
obsidian-clipper
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
0.11.2
src/utils/content-script-utils.ts
25 строк
822 B
Steph Ango
Highlighter mode (#84)
10 окт 2024, 01:07
Не верифицирован
10 окт 2024, 01:07
9b564a2
Код
Авторство
О чём код?
import browser from './browser-polyfill'; import { isValidUrl } from './active-tab-manager'; export async function ensureContentScriptLoaded(tabId: number): Promise<void> { try { // First, get the tab information const tab = await browser.tabs.get(tabId); // Check if the URL is valid before proceeding if (!tab.url || !isValidUrl(tab.url)) { console.log(`Skipping content script injection for invalid URL: ${tab.url}`); return; } // Attempt to send a message to the content script await browser.tabs.sendMessage(tabId, { action: "ping" }); } catch (error) { // If the message fails, the content script is not loaded, so inject it console.log('Content script not loaded, injecting...'); await browser.scripting.executeScript({ target: { tabId: tabId }, files: ['content.js'] }); } }