Files
UT-Registration-Plus/src/views/lib/openNewTabFromContentScript.ts
Diego Perez a537d17a2f feat: inline chrome-extension-toolkit (#744)
* feat(build): inline chrome-extension-toolkit

fix: tsconfig

docs: add chrome-extension-toolkit README.md

chore: update imports

fix: stores

fix: chrome-extension-toolkit ForegroundMessenger

fix: calendarBackgroundHandler

fix: format and lint

fix: path alias

fix: add jsdom env and fix imports

Co-authored-by: Sriram Hariharan <sghsri@gmail.com>

* build: vite storybook config crx toolkit line

---------

Co-authored-by: Sriram Hariharan <sghsri@gmail.com>
Co-authored-by: Derek <derex1987@gmail.com>
2026-02-11 00:50:27 -06:00

26 lines
880 B
TypeScript

import { createMessenger } from '@chrome-extension-toolkit';
type MyMessages = {
openNewTab: (data: { url: string }) => void;
};
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) {
messenger
.openNewTab({ url }) // Fix: Pass the url as a property of an object
.then(() => {
console.log('New tab opened with URL:', url);
})
.catch(error => {
console.error('Error opening new tab:', error);
});
}