feat: can open tabs, updated injected popup heading. basically done

This commit is contained in:
knownotunknown
2024-02-20 21:20:37 -06:00
committed by doprz
parent 35f3c72250
commit 35fab34445
6 changed files with 130 additions and 90 deletions

View File

@@ -0,0 +1,25 @@
import { createMessenger } from "chrome-extension-toolkit";
type MyMessages = {
openNewTab: {
data: { url: string };
};
};
const messenger = createMessenger<MyMessages>('background');
/**
* Content scripts and background scripts are isolated environments.
* Content scripts are where our code interacting with the webpage lives,
* whereas the background script is where we can open a tab from.
* This function allows us to open a new tab from the content script by communicating
* with the background script.
*/
export async function openTabFromContentScript(url: string) {
// @ts-ignore
messenger.openNewTab({ url }).then(() => {
console.log('New tab opened with URL:', url);
}).catch((error) => {
console.error('Error opening new tab:', error);
});
}