@tomzhu1024/workspace-api-for-chrome

Provide workspace management ability for Chrome

Usage no npm install needed!

<script type="module">
  import tomzhu1024WorkspaceApiForChrome from 'https://cdn.skypack.dev/@tomzhu1024/workspace-api-for-chrome';
</script>

README

Workspace API for Chrome

How to use

Install the package:

npm add -D workspace-api-for-chrome

Create a new window as the new workspace,

import { WindowsService } from 'workspace-api-for-chrome';
const winId = await WindowsService.create('https://github.com/');

Initialize the workspace with a specified windowId,

import { Workspace } from 'workspace-api-for-chrome';
const workspace = new Workspace(winId);

Serialize the workspace,

const jsonFormatString: string = await workspace.read();

De-serialize the workspace,

workspace.write(jsonFormatString).then();

The structure of the JSON data,

type IMessage = {
  tabs: string[]; // the array of tab information
  activeIndex: number;  // the index of the active tab
};

Furthermore, some helpful tools are available. For instance, to register browser listeners for tab events in a batch way,

import { ListenersService } from 'workspace-api-for-chrome';
const listenersService = new ListenersService(() => {
  // do something here
});