Open alexstrat opened 5 years ago
// responsible to provide assets (files, manifest..) of a given extension
interface ExtensionAssetsProvider {
extensionId: string
asycn getManifest: () => object
// readfile('main.html') will find `main.html` in extension folder
readFile: (relativePath) => {mimeType: string, data: Stream }
}
interface BackgroundPagesManager() {
start(extensionId: string, extensionsAssets: ExtensionAssetsProvider): BackgroundPage,
stop(extensionId: string)
}
interface ContentScriptsInjector() {
addContentScriptsForExtension(extensionId: string, extensionsAssets: ExtensionAssetsProvider)
removeContentScriptsForExtension(extensionId: string)
}
Moreover, in ChromeAPIHandler
, I think we should abstract the use of IPC to ease the unit-tesing.
A candidate for this: https://github.com/JsCommunity/json-rpc-peer that can use stream
s of JSON-RPC
chrome-extension.js
is a big, but ugly, file that holds big parts of logic. If we want to make the lib more easy to work on, we should refactor this file.chrome-extension.js
expose 2 public APIs:addExtension(extensionId, srcDirectory)
removeExtension(extensionId)
addExtension
is responsible for:manifest.json
ChromeAPIHandler
forstorage
,webRequest
,windows
ChromeAPIHandler
) forruntime
,tabs
,web navigation
(others ?)chrome.devtools
APIs~chrome-extension.js
): servechrome-extension://*
inengine/protocol
These responsibilities could be split into several modules.