extension-create 4.0.18 → 4.0.19-canary.1785200797.ce99a79e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@ export declare function createDirectoryError(projectName: string, error: unknown
8
8
  export declare function writingTypeDefinitions(projectName: string): string;
9
9
  export declare function writingTypeDefinitionsError(error: unknown): string;
10
10
  export declare function installingFromTemplate(projectName: string, templateName: string): string;
11
- export declare function installingFromTemplateError(projectName: string, template: string, error: unknown): string;
11
+ export declare function installingFromTemplateError(template: string, error: unknown): string;
12
12
  export declare function templateFetchTimedOut(templateName: string, ms: number): string;
13
13
  export declare function templateNotFoundInCatalog(templateName: string, error?: unknown): string;
14
14
  export declare function templateDownloadFailed(templateName: string, error: unknown): string;
@@ -17,19 +17,19 @@ export declare function initializingGitSkipped(projectName: string, reason: stri
17
17
  export declare function installingDependencies(): string;
18
18
  export declare function foundSpecializedDependencies(count: number): string;
19
19
  export declare function installingProjectIntegrations(integrations: string[]): string;
20
- export declare function installingDependenciesFailed(gitCommand: string, gitArgs: string[], code: number | null): string;
20
+ export declare function installingDependenciesFailed(pmCommand: string, pmArgs: string[], code: number | null): string;
21
21
  export declare function installingDependenciesProcessError(projectName: string, error: unknown): string;
22
22
  export declare function cantInstallDependencies(projectName: string, error: unknown): string;
23
23
  export declare function writingPackageJsonMetadata(): string;
24
- export declare function writingPackageJsonMetadataError(projectName: string, error: unknown): string;
24
+ export declare function writingPackageJsonMetadataError(error: unknown): string;
25
25
  export declare function writingDenoJsonc(): string;
26
- export declare function writingDenoJsoncError(projectName: string, error: unknown): string;
26
+ export declare function writingDenoJsoncError(error: unknown): string;
27
27
  export declare function writingTemplateProvenance(): string;
28
28
  export declare function writingTemplateProvenanceError(error: unknown): string;
29
29
  export declare function writingManifestJsonMetadata(): string;
30
- export declare function writingManifestJsonMetadataError(projectName: string, error: unknown): string;
30
+ export declare function writingManifestJsonMetadataError(error: unknown): string;
31
31
  export declare function writingReadmeMetaData(): string;
32
32
  export declare function writingGitIgnore(): string;
33
- export declare function writingReadmeMetaDataEError(projectName: string, error: unknown): string;
33
+ export declare function writingReadmeMetaDataError(error: unknown): string;
34
34
  export declare function writingDirectoryError(error: unknown): string;
35
- export declare function cantSetupBuiltInTests(projectName: string, error: unknown): string;
35
+ export declare function cantSetupBuiltInTests(error: unknown): string;
package/dist/module.cjs CHANGED
@@ -181,7 +181,7 @@ function installingFromTemplate(projectName, templateName) {
181
181
  if ('init' === templateName || "javascript" === templateName) return `${prefix('info')} Install ${external_pintor_default().blue(projectName)}.`;
182
182
  return `${prefix('info')} Install ${external_pintor_default().blue(projectName)} from the template ${external_pintor_default().yellow(templateName)}.`;
183
183
  }
184
- function installingFromTemplateError(projectName, template, error) {
184
+ function installingFromTemplateError(template, error) {
185
185
  return `${prefix('error')} Couldn't find the template ${external_pintor_default().yellow(template)}.\n${external_pintor_default().red('Choose a template name from')} ${external_pintor_default().blue('extension create --help')}${external_pintor_default().red(', or pass a GitHub URL.')}\n${external_pintor_default().red(String(error))}`;
186
186
  }
187
187
  function templateFetchTimedOut(templateName, ms) {
@@ -215,8 +215,8 @@ function installingProjectIntegrations(integrations) {
215
215
  const tools = formatList(integrations.map((name)=>external_pintor_default().yellow(name)));
216
216
  return `${prefix('info')} Install the dependencies for ${tools}.\n${external_pintor_default().gray('This can take a moment.')}`;
217
217
  }
218
- function installingDependenciesFailed(gitCommand, gitArgs, code) {
219
- return `${prefix('error')} The command ${external_pintor_default().yellow(gitCommand)} ${external_pintor_default().yellow(gitArgs.join(' '))} failed with exit code ${external_pintor_default().yellow(String(code))}.\n${external_pintor_default().red('Run it yourself to see the full error.')}`;
218
+ function installingDependenciesFailed(pmCommand, pmArgs, code) {
219
+ return `${prefix('error')} The command ${external_pintor_default().yellow(pmCommand)} ${external_pintor_default().yellow(pmArgs.join(' '))} failed with exit code ${external_pintor_default().yellow(String(code))}.\n${external_pintor_default().red('Run it yourself to see the full error.')}`;
220
220
  }
221
221
  function installingDependenciesProcessError(projectName, error) {
222
222
  return `${prefix('error')} The install process for ${external_pintor_default().blue(projectName)} exited unexpectedly.\n${external_pintor_default().red('Run the install command yourself to see the full error.')}\n${external_pintor_default().red(String(error))}`;
@@ -227,13 +227,13 @@ function cantInstallDependencies(projectName, error) {
227
227
  function writingPackageJsonMetadata() {
228
228
  return `${prefix('debug')} create write file=package.json`;
229
229
  }
230
- function writingPackageJsonMetadataError(projectName, error) {
230
+ function writingPackageJsonMetadataError(error) {
231
231
  return `${prefix('error')} Couldn't write ${external_pintor_default().yellow('package.json')}.\n${external_pintor_default().red('Check the file permissions, then try again.')}\n${external_pintor_default().red(String(error))}`;
232
232
  }
233
233
  function writingDenoJsonc() {
234
234
  return `${prefix('debug')} create write file=deno.jsonc`;
235
235
  }
236
- function writingDenoJsoncError(projectName, error) {
236
+ function writingDenoJsoncError(error) {
237
237
  return `${prefix('error')} Couldn't write ${external_pintor_default().yellow('deno.jsonc')}.\n${external_pintor_default().red('Check the file permissions, then try again.')}\n${external_pintor_default().red(String(error))}`;
238
238
  }
239
239
  function writingTemplateProvenance() {
@@ -245,7 +245,7 @@ function writingTemplateProvenanceError(error) {
245
245
  function writingManifestJsonMetadata() {
246
246
  return `${prefix('debug')} create write file=manifest.json`;
247
247
  }
248
- function writingManifestJsonMetadataError(projectName, error) {
248
+ function writingManifestJsonMetadataError(error) {
249
249
  return `${prefix('error')} Couldn't write ${external_pintor_default().yellow('manifest.json')}.\n${external_pintor_default().red('Check the file permissions, then try again.')}\n${external_pintor_default().red(String(error))}`;
250
250
  }
251
251
  function writingReadmeMetaData() {
@@ -254,13 +254,13 @@ function writingReadmeMetaData() {
254
254
  function writingGitIgnore() {
255
255
  return `${prefix('debug')} create write file=.gitignore`;
256
256
  }
257
- function writingReadmeMetaDataEError(projectName, error) {
257
+ function writingReadmeMetaDataError(error) {
258
258
  return `${prefix('error')} Couldn't write ${external_pintor_default().yellow('README.md')}.\n${external_pintor_default().red('Check the file permissions, then try again.')}\n${external_pintor_default().red(String(error))}`;
259
259
  }
260
260
  function writingDirectoryError(error) {
261
261
  return `${prefix('error')} Couldn't check whether the directory is writable.\n${external_pintor_default().red('Check the path and its permissions, then try again.')}\n${external_pintor_default().red(String(error))}`;
262
262
  }
263
- function cantSetupBuiltInTests(projectName, error) {
263
+ function cantSetupBuiltInTests(error) {
264
264
  return `${prefix('error')} Couldn't set up the built-in tests.\n${external_pintor_default().red('The extension itself is fine. Re-run create, or skip the tests.')}\n${external_pintor_default().red(String(error))}`;
265
265
  }
266
266
  const promises_namespaceObject = require("node:fs/promises");
@@ -674,7 +674,7 @@ async function importExternalTemplate(projectPath, projectName, template, logger
674
674
  } catch (error) {
675
675
  if (error instanceof TemplateNotFoundError) logger.error(templateNotFoundInCatalog(templateName, error.cause));
676
676
  else if (error instanceof TemplateDownloadError) logger.error(templateDownloadFailed(templateName, error));
677
- else logger.error(installingFromTemplateError(projectName, templateName, error));
677
+ else logger.error(installingFromTemplateError(templateName, error));
678
678
  await promises_namespaceObject.rm(projectPath, {
679
679
  recursive: true,
680
680
  force: true
@@ -1165,12 +1165,12 @@ async function installInternalDependencies(projectPath, logger) {
1165
1165
  const optionalPlan = resolveMissingOptionalDeps(developRoot, projectPath);
1166
1166
  if (optionalPlan.dependencies.length > 0) await installOptionalDependencies(developRoot, projectPath, optionalPlan, logger);
1167
1167
  }
1168
- async function setupBuiltInTests(projectPath, projectName, logger) {
1168
+ async function setupBuiltInTests(projectPath, logger) {
1169
1169
  try {
1170
1170
  const testSpecPath = external_node_path_namespaceObject.join(projectPath, 'tests', 'templates.spec.ts');
1171
1171
  if (external_node_fs_namespaceObject.existsSync(testSpecPath)) external_node_fs_namespaceObject.unlinkSync(testSpecPath);
1172
1172
  } catch (error) {
1173
- logger.error(cantSetupBuiltInTests(projectName, error));
1173
+ logger.error(cantSetupBuiltInTests(error));
1174
1174
  throw error;
1175
1175
  }
1176
1176
  }
@@ -1242,7 +1242,7 @@ function resolveExtensionDevDependencyVersion(cliVersion) {
1242
1242
  if (!resolved) return 'latest';
1243
1243
  return resolved.includes('-') ? resolved : `^${resolved}`;
1244
1244
  }
1245
- async function overridePackageJson(projectPath, projectName, { template = "javascript", cliVersion }, logger) {
1245
+ async function overridePackageJson(projectPath, { template = "javascript", cliVersion }, logger) {
1246
1246
  const extensionBinary = await resolveExtensionBinary();
1247
1247
  const candidatePath = external_node_path_namespaceObject.join(projectPath, 'package.json');
1248
1248
  let packageJson = {};
@@ -1319,7 +1319,7 @@ async function overridePackageJson(projectPath, projectName, { template = "javas
1319
1319
  if (isDebug()) logger.log(writingPackageJsonMetadata());
1320
1320
  await promises_namespaceObject.writeFile(external_node_path_namespaceObject.join(projectPath, 'package.json'), `${JSON.stringify(packageMetadata, null, 2)}\n`);
1321
1321
  } catch (error) {
1322
- logger.error(writingPackageJsonMetadataError(projectName, error));
1322
+ logger.error(writingPackageJsonMetadataError(error));
1323
1323
  throw error;
1324
1324
  }
1325
1325
  }
@@ -1363,7 +1363,7 @@ async function collectTemplateImports(projectPath, cliVersion) {
1363
1363
  imports.extension = `npm:extension@${extensionVersion}`;
1364
1364
  return imports;
1365
1365
  }
1366
- async function writeDenoJsonc(projectPath, projectName, { template = "javascript", cliVersion, primary = false }, logger) {
1366
+ async function writeDenoJsonc(projectPath, { template = "javascript", cliVersion, primary = false }, logger) {
1367
1367
  if (!isDenoRuntime()) return;
1368
1368
  for (const existing of [
1369
1369
  'deno.jsonc',
@@ -1379,7 +1379,7 @@ async function writeDenoJsonc(projectPath, projectName, { template = "javascript
1379
1379
  force: true
1380
1380
  });
1381
1381
  } catch (error) {
1382
- logger.error(writingDenoJsoncError(projectName, error));
1382
+ logger.error(writingDenoJsoncError(error));
1383
1383
  throw error;
1384
1384
  }
1385
1385
  }
@@ -1500,7 +1500,7 @@ async function findManifestJsonPath(projectPath) {
1500
1500
  }
1501
1501
  throw new Error(`Could not locate manifest.json under ${projectPath}. Checked common paths and searched up to depth ${manifestSearchMaxDepth}.`);
1502
1502
  }
1503
- async function writeManifestJson(projectPath, projectName, logger) {
1503
+ async function writeManifestJson(projectPath, logger) {
1504
1504
  const manifestJsonPath = await findManifestJsonPath(projectPath);
1505
1505
  const manifestJsonContent = await promises_namespaceObject.readFile(manifestJsonPath);
1506
1506
  const manifestJson = JSON.parse(manifestJsonContent.toString());
@@ -1513,7 +1513,7 @@ async function writeManifestJson(projectPath, projectName, logger) {
1513
1513
  if (isDebug()) logger.log(writingManifestJsonMetadata());
1514
1514
  await promises_namespaceObject.writeFile(manifestJsonPath, JSON.stringify(manifestMetadata, null, 2));
1515
1515
  } catch (error) {
1516
- logger.error(writingManifestJsonMetadataError(projectName, error));
1516
+ logger.error(writingManifestJsonMetadataError(error));
1517
1517
  throw error;
1518
1518
  }
1519
1519
  }
@@ -1545,7 +1545,7 @@ async function writeReadmeFile(projectPath, projectName, logger) {
1545
1545
  });
1546
1546
  await promises_namespaceObject.writeFile(external_node_path_namespaceObject.join(projectPath, 'README.md'), readme);
1547
1547
  } catch (error) {
1548
- logger.error(writingReadmeMetaDataEError(projectName, error));
1548
+ logger.error(writingReadmeMetaDataError(error));
1549
1549
  throw error;
1550
1550
  }
1551
1551
  }
@@ -1607,17 +1607,17 @@ async function extensionCreate(projectNameInput, { cliVersion, template = "javas
1607
1607
  await createDirectory(projectPath, projectName, logger);
1608
1608
  const templateProvenance = await importExternalTemplate(projectPath, projectName, template, logger);
1609
1609
  const isMonorepoTemplate = String(template).toLowerCase().includes('monorepo');
1610
- if (isDenoRuntime() && !isMonorepoTemplate) await writeDenoJsonc(projectPath, projectName, {
1610
+ if (isDenoRuntime() && !isMonorepoTemplate) await writeDenoJsonc(projectPath, {
1611
1611
  template,
1612
1612
  cliVersion,
1613
1613
  primary: true
1614
1614
  }, logger);
1615
1615
  else {
1616
- await overridePackageJson(projectPath, projectName, {
1616
+ await overridePackageJson(projectPath, {
1617
1617
  template,
1618
1618
  cliVersion
1619
1619
  }, logger);
1620
- await writeDenoJsonc(projectPath, projectName, {
1620
+ await writeDenoJsonc(projectPath, {
1621
1621
  template
1622
1622
  }, logger);
1623
1623
  }
@@ -1627,10 +1627,10 @@ async function extensionCreate(projectNameInput, { cliVersion, template = "javas
1627
1627
  await installInternalDependencies(projectPath, logger);
1628
1628
  }
1629
1629
  await writeReadmeFile(projectPath, projectName, logger);
1630
- await writeManifestJson(projectPath, projectName, logger);
1630
+ await writeManifestJson(projectPath, logger);
1631
1631
  await initializeGitRepository(projectPath, projectName, logger);
1632
1632
  await writeGitignore(projectPath, logger);
1633
- await setupBuiltInTests(projectPath, projectName, logger);
1633
+ await setupBuiltInTests(projectPath, logger);
1634
1634
  if (isTypeScriptTemplate(template)) await generateExtensionTypes(projectPath, projectName, logger);
1635
1635
  const successfulInstall = await successfullInstall(projectPath, projectName, Boolean(install));
1636
1636
  logger.log(successfulInstall);
@@ -1,4 +1,4 @@
1
- export declare function setupBuiltInTests(projectPath: string, projectName: string, logger: {
1
+ export declare function setupBuiltInTests(projectPath: string, logger: {
2
2
  log(...args: unknown[]): void;
3
3
  error(...args: unknown[]): void;
4
4
  }): Promise<void>;
@@ -3,7 +3,7 @@ interface WriteDenoJsoncOptions {
3
3
  cliVersion?: string;
4
4
  primary?: boolean;
5
5
  }
6
- export declare function writeDenoJsonc(projectPath: string, projectName: string, { template, cliVersion, primary }: WriteDenoJsoncOptions, logger: {
6
+ export declare function writeDenoJsonc(projectPath: string, { template, cliVersion, primary }: WriteDenoJsoncOptions, logger: {
7
7
  log(...args: unknown[]): void;
8
8
  error(...args: unknown[]): void;
9
9
  }): Promise<void>;
@@ -1,4 +1,4 @@
1
- export declare function writeManifestJson(projectPath: string, projectName: string, logger: {
1
+ export declare function writeManifestJson(projectPath: string, logger: {
2
2
  log(...args: unknown[]): void;
3
3
  error(...args: unknown[]): void;
4
4
  }): Promise<void>;
@@ -6,7 +6,7 @@ interface OverridePackageJsonOptions {
6
6
  cliVersion?: string;
7
7
  }
8
8
  export declare function resolveExtensionDevDependencyVersion(cliVersion?: string): string;
9
- export declare function overridePackageJson(projectPath: string, projectName: string, { template, cliVersion }: OverridePackageJsonOptions, logger: {
9
+ export declare function overridePackageJson(projectPath: string, { template, cliVersion }: OverridePackageJsonOptions, logger: {
10
10
  log(...args: unknown[]): void;
11
11
  error(...args: unknown[]): void;
12
12
  }): Promise<void>;
package/package.json CHANGED
@@ -25,7 +25,7 @@
25
25
  "templates"
26
26
  ],
27
27
  "name": "extension-create",
28
- "version": "4.0.18",
28
+ "version": "4.0.19-canary.1785200797.ce99a79e",
29
29
  "description": "The standalone extension creation engine for Extension.js",
30
30
  "author": {
31
31
  "name": "Cezar Augusto",
@@ -1,5 +0,0 @@
1
- {
2
- "createdWith": "extension-create@4.0.17",
3
- "template": "javascript",
4
- "source": "bundled"
5
- }
@@ -1,41 +0,0 @@
1
- <a href="https://extension.js.org" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/Powered%20by%20%7C%20Extension.js-0971fe" alt="Powered by Extension.js" align="right" /></a>
2
-
3
- # test-template-javascript
4
-
5
- > JavaScript-based extension with a sidebar panel. Adds a sidebar with a simple page.
6
-
7
-
8
- ![screenshot](./public/screenshot.png)
9
- ## Commands
10
-
11
- ### dev
12
-
13
- Run the extension in development mode. Target a browser with `--browser`:
14
-
15
- ```bash
16
- pnpm run dev
17
- pnpm run dev -- --browser=firefox
18
- pnpm run dev -- --browser=edge
19
- ```
20
-
21
- ### build
22
-
23
- Build for production. Convenience scripts target each browser:
24
-
25
- ```bash
26
- pnpm run build # Chrome (default)
27
- pnpm run build:firefox
28
- pnpm run build:edge
29
- ```
30
-
31
- ### preview
32
-
33
- Preview the production build in the browser:
34
-
35
- ```bash
36
- pnpm run preview
37
- ```
38
-
39
- ## Learn more
40
-
41
- [Extension.js docs](https://extension.js.org).
@@ -1,65 +0,0 @@
1
- # Store metadata
2
-
3
- Starter file generated from this template's manifest. Every store asks
4
- for this material at submission time; keep it current as the code
5
- changes instead of rewriting it at the end. Replace the placeholder
6
- lines marked TODO before you submit.
7
-
8
- Last updated: 2026-07-20
9
-
10
- ## Listing
11
-
12
- - Name: JavaScript Sidebar Example
13
- - Summary: JavaScript-based extension with a sidebar panel.
14
- - Description: TODO write two or three short paragraphs of user
15
- benefits. Describe what the user sees and gains, not how the code
16
- works.
17
- - Category: TODO pick one per store (for example Productivity).
18
- - Screenshots: TODO at least one 1280x800 screenshot per store.
19
-
20
- ## Privacy and data use
21
-
22
- - This template collects, stores, and transmits no user data.
23
- - The manifest declares data_collection_permissions: none for
24
- Firefox, which matches this behavior. If you add data collection,
25
- update the declaration, this section, and your privacy policy in
26
- the same change.
27
- - Privacy policy URL: TODO required by every store once you collect
28
- any data.
29
-
30
- ## Chrome Web Store
31
-
32
- ### Single purpose
33
-
34
- JavaScript-based extension with a sidebar panel.
35
-
36
- ### Permissions justification
37
-
38
- - sidePanel (Chromium only): Renders the extension's main interface in the browser side panel.
39
- - Content script match <all_urls>: The content script runs on the pages the user visits to render the extension's on-page interface. Narrow this to the specific sites your extension needs before submitting.
40
-
41
- ## Firefox Add-ons
42
-
43
- ### Reviewer notes
44
-
45
- TODO steps a reviewer needs to exercise the extension, plus test
46
- credentials if sign-in is required. The build is bundled, so AMO
47
- requires a source zip; include build-from-source instructions:
48
- npm install, then npm run build. The dist output matches the upload.
49
-
50
- ### Release notes
51
-
52
- TODO user-facing notes for the version you are submitting.
53
-
54
- ## Edge Add-ons
55
-
56
- ### Certification notes
57
-
58
- TODO anything the certification team needs to test the extension,
59
- including test steps and credentials. Mirrors the Firefox reviewer
60
- notes in most cases.
61
-
62
- ## Version history
63
-
64
- - 1.0.0 (unreleased): initial version from the javascript template.
65
- Not yet submitted to any store.
@@ -1,19 +0,0 @@
1
- /** @type {import('extension').FileConfig} */
2
- // Extension.js uses a fresh profile on every run.
3
- // Prefer that default? Remove the profile config below.
4
- const profile = (name) => `./dist/extension-profile-${name}`
5
- const ciFlags = process.env.CI ? ['--no-sandbox', '--disable-gpu'] : []
6
-
7
- export default {
8
- browser: {
9
- chrome: {profile: profile('chrome'), browserFlags: ciFlags},
10
- chromium: {profile: profile('chromium'), browserFlags: ciFlags},
11
- edge: {profile: profile('edge'), browserFlags: ciFlags},
12
- firefox: {profile: profile('firefox')},
13
- 'chromium-based': {
14
- profile: profile('chromium-based'),
15
- browserFlags: ciFlags
16
- },
17
- 'gecko-based': {profile: profile('gecko-based')}
18
- }
19
- }
@@ -1,32 +0,0 @@
1
- {
2
- "private": true,
3
- "name": "test-template-javascript",
4
- "description": "JavaScript-based extension with a sidebar panel. Adds a sidebar with a simple page.",
5
- "version": "1.0.0",
6
- "license": "MIT",
7
- "type": "module",
8
- "author": {
9
- "name": "Your Name",
10
- "email": "your@email.com",
11
- "url": "https://yourwebsite.com"
12
- },
13
- "scripts": {
14
- "dev": "extension dev",
15
- "start": "extension start",
16
- "build": "extension build",
17
- "preview": "extension preview",
18
- "build:chrome": "extension build --browser chrome",
19
- "build:firefox": "extension build --browser firefox",
20
- "build:edge": "extension build --browser edge"
21
- },
22
- "dependencies": {},
23
- "devDependencies": {
24
- "extension": "^4.0.17"
25
- },
26
- "packageManager": "pnpm@10.28.0",
27
- "pnpm": {
28
- "ignoredBuiltDependencies": [
29
- "less"
30
- ]
31
- }
32
- }
@@ -1,44 +0,0 @@
1
- console.log(
2
- '[From the background context] Hello from the background worker/script!'
3
- )
4
-
5
- const isFirefoxLike =
6
- import.meta.env.EXTENSION_PUBLIC_BROWSER === 'firefox' ||
7
- import.meta.env.EXTENSION_PUBLIC_BROWSER === 'gecko-based'
8
-
9
- if (isFirefoxLike) {
10
- browser.browserAction.onClicked.addListener(() => {
11
- browser.sidebarAction.open()
12
- })
13
-
14
- browser.runtime.onMessage.addListener((message) => {
15
- if (!message || message.type !== 'openSidebar') return
16
-
17
- browser.sidebarAction.open()
18
- })
19
- }
20
-
21
- if (!isFirefoxLike) {
22
- // setPanelBehavior only affects FUTURE action clicks, registering it
23
- // inside onClicked would swallow the first toolbar click.
24
- chrome.sidePanel.setPanelBehavior({openPanelOnActionClick: true})
25
- }
26
-
27
- chrome.runtime.onMessage.addListener((message) => {
28
- if (!message || message.type !== 'openSidebar') return
29
-
30
- chrome.sidePanel.setPanelBehavior({openPanelOnActionClick: true})
31
-
32
- if (!chrome.sidePanel.open) return
33
-
34
- chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
35
- const activeTabId = tabs?.[0]?.id
36
- if (!activeTabId) return
37
-
38
- try {
39
- chrome.sidePanel.open({tabId: activeTabId})
40
- } catch (error) {
41
- console.error(error)
42
- }
43
- })
44
- })
@@ -1,41 +0,0 @@
1
- import logo from '../images/icon.png'
2
-
3
- export default function createContentApp() {
4
- const container = document.createElement('div')
5
- container.className = 'content_script'
6
-
7
- const pill = document.createElement('button')
8
- pill.type = 'button'
9
- pill.className = 'content_pill'
10
- pill.setAttribute('aria-label', 'Open sidebar')
11
- pill.addEventListener('click', () => {
12
- try {
13
- if (
14
- import.meta.env.EXTENSION_PUBLIC_BROWSER === 'firefox' ||
15
- import.meta.env.EXTENSION_PUBLIC_BROWSER === 'gecko-based'
16
- ) {
17
- browser.runtime.sendMessage({type: 'openSidebar'})
18
- } else {
19
- chrome.runtime.sendMessage({type: 'openSidebar'})
20
- }
21
- } catch (error) {
22
- console.error(error)
23
- }
24
- })
25
-
26
- const img = document.createElement('img')
27
- img.className = 'content_pill_logo'
28
- img.src = logo
29
- img.alt = ''
30
- img.setAttribute('aria-hidden', 'true')
31
-
32
- const text = document.createElement('span')
33
- text.className = 'content_pill_text'
34
- text.textContent = 'Open sidebar'
35
-
36
- pill.appendChild(img)
37
- pill.appendChild(text)
38
- container.appendChild(pill)
39
-
40
- return container
41
- }
@@ -1,44 +0,0 @@
1
- import createContentApp from './ContentApp.js'
2
- import './styles.css'
3
-
4
- console.log('[From the page context] Hello from content_scripts!')
5
-
6
- /**
7
- * Extension.js content_script entrypoint. The framework calls this on
8
- * injection and calls the returned function on HMR/teardown to clean up.
9
- * Do not invoke it yourself.
10
- */
11
- export default function initial() {
12
- const rootDiv = document.createElement('div')
13
- rootDiv.setAttribute('data-extension-root', 'true')
14
- // Isolate the host from page styles (e.g. example.com ships div{opacity:.8},
15
- // which would otherwise fade the whole widget): the shadow DOM only protects
16
- // descendants; the host element itself still takes page CSS.
17
- rootDiv.style.cssText = 'all: initial !important'
18
- document.body.appendChild(rootDiv)
19
-
20
- // Injecting content_scripts inside a shadow dom
21
- // prevents conflicts with the host page's styles.
22
- // This way, styles from the extension won't leak into the host page.
23
- const shadowRoot = rootDiv.attachShadow({mode: 'open'})
24
-
25
- const styleElement = document.createElement('style')
26
- shadowRoot.appendChild(styleElement)
27
-
28
- fetchCSS().then((response) => (styleElement.textContent = response))
29
-
30
- // Render ContentApp inside shadow root
31
- const container = createContentApp()
32
- shadowRoot.appendChild(container)
33
-
34
- return () => {
35
- rootDiv.remove()
36
- }
37
- }
38
-
39
- async function fetchCSS() {
40
- const cssUrl = new URL('./styles.css', import.meta.url)
41
- const response = await fetch(cssUrl)
42
- const text = await response.text()
43
- return response.ok ? text : Promise.reject(text)
44
- }
@@ -1,45 +0,0 @@
1
- .content_script {
2
- position: absolute;
3
- right: 0.75rem;
4
- bottom: 0.75rem;
5
- z-index: 9999;
6
- }
7
-
8
- .content_pill {
9
- -webkit-font-smoothing: antialiased;
10
- -moz-osx-font-smoothing: grayscale;
11
- appearance: none;
12
- border: none;
13
- outline: none;
14
- cursor: pointer;
15
- display: inline-flex;
16
- align-items: center;
17
- gap: 0.5rem;
18
- background: var(--sidebar-bg, #0a0c10);
19
- color: var(--sidebar-text, #c9c9c9);
20
- padding: 0.5rem 1rem 0.5rem 0.5rem;
21
- border-radius: 9999px;
22
- box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
23
- }
24
-
25
- .content_pill:hover {
26
- background: #11151c;
27
- }
28
-
29
- .content_pill_logo {
30
- height: 1.5rem;
31
- border-radius: 9999px;
32
- background: rgba(255, 255, 255, 0.08);
33
- object-fit: contain;
34
- aspect-ratio: 1 / 1;
35
- padding: 0.125rem;
36
- }
37
-
38
- .content_pill_text {
39
- font-size: 0.85rem;
40
- font-weight: 600;
41
- line-height: 1;
42
- font-family:
43
- -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
44
- Arial, "Noto Sans", sans-serif;
45
- }
@@ -1,72 +0,0 @@
1
- {
2
- "$schema": "https://json.schemastore.org/chrome-manifest.json",
3
- "chromium:manifest_version": 3,
4
- "firefox:manifest_version": 2,
5
- "version": "1.0.0",
6
- "firefox:browser_specific_settings": {
7
- "gecko": {
8
- "data_collection_permissions": {
9
- "required": [
10
- "none"
11
- ]
12
- }
13
- }
14
- },
15
- "name": "test-template-javascript",
16
- "description": "JavaScript-based extension with a sidebar panel. Adds a sidebar with a simple page.",
17
- "icons": {
18
- "16": "images/icon.png",
19
- "32": "images/icon.png",
20
- "48": "images/icon.png",
21
- "64": "images/icon.png",
22
- "128": "images/icon.png"
23
- },
24
- "chromium:action": {
25
- "default_icon": {
26
- "16": "images/icon.png",
27
- "32": "images/icon.png",
28
- "48": "images/icon.png",
29
- "64": "images/icon.png",
30
- "128": "images/icon.png"
31
- },
32
- "default_title": "Open Side Panel"
33
- },
34
- "firefox:browser_action": {
35
- "default_icon": {
36
- "16": "images/icon.png",
37
- "32": "images/icon.png",
38
- "48": "images/icon.png",
39
- "64": "images/icon.png",
40
- "128": "images/icon.png"
41
- },
42
- "default_title": "Open Side Panel"
43
- },
44
- "chromium:side_panel": {
45
- "default_path": "sidebar/index.html",
46
- "default_title": "Side Panel Content"
47
- },
48
- "firefox:sidebar_action": {
49
- "default_panel": "sidebar/index.html",
50
- "default_title": "Side Panel Content"
51
- },
52
- "chromium:permissions": [
53
- "sidePanel"
54
- ],
55
- "background": {
56
- "chromium:service_worker": "background.js",
57
- "firefox:scripts": [
58
- "background.js"
59
- ]
60
- },
61
- "content_scripts": [
62
- {
63
- "matches": [
64
- "<all_urls>"
65
- ],
66
- "js": [
67
- "content/scripts.js"
68
- ]
69
- }
70
- ],
71
- "author": "Your Name"
72
- }
@@ -1,28 +0,0 @@
1
- import './styles.css'
2
- import javascriptLogo from '../images/icon.png'
3
-
4
- function SidebarApp() {
5
- const root = document.getElementById('root')
6
- if (!root) return
7
-
8
- root.innerHTML = `
9
- <div class="sidebar_app">
10
- <img
11
- class="sidebar_logo"
12
- src="${javascriptLogo}"
13
- alt="The JavaScript logo"
14
- />
15
- <h1 class="sidebar_title">Sidebar Panel</h1>
16
- <p class="sidebar_description">
17
- Learn more in the
18
- <a
19
- href="https://extension.js.org"
20
- target="_blank" rel="noopener noreferrer"
21
- >Extension.js docs</a>
22
- .
23
- </p>
24
- </div>
25
- `
26
- }
27
-
28
- SidebarApp()
@@ -1,13 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1" />
6
- <title>JavaScript Sidebar</title>
7
- </head>
8
- <body>
9
- <noscript>You need to enable JavaScript to run this extension.</noscript>
10
- <div id="root"></div>
11
- </body>
12
- <script src="./scripts.js"></script>
13
- </html>
@@ -1,4 +0,0 @@
1
- import './SidebarApp.js'
2
- import './styles.css'
3
-
4
- console.log('[From the sidebar page context] Hello regular page!')
@@ -1,60 +0,0 @@
1
- /* @import 'sakura.css'; */
2
-
3
- :root {
4
- --sidebar-margin: 1rem;
5
- --sidebar-bg: #0a0c10;
6
- --sidebar-text: #c9c9c9;
7
- --sidebar-link: #e5e7eb;
8
- --sidebar-border: #c9c9c9;
9
- }
10
-
11
- body {
12
- background-color: var(--sidebar-bg);
13
- color: var(--sidebar-text);
14
- height: 100vh;
15
- margin: var(--sidebar-margin);
16
- border-radius: 6px;
17
- display: flex;
18
- justify-content: center;
19
- align-items: center;
20
- overflow: hidden;
21
- }
22
-
23
- .sidebar_app {
24
- display: flex;
25
- flex-direction: column;
26
- align-items: center;
27
- padding: 0 1rem;
28
- text-align: center;
29
- max-height: 100vh;
30
- overflow-y: auto;
31
- }
32
-
33
- .sidebar_logo {
34
- width: 72px;
35
- margin: 0 auto 1rem;
36
- }
37
-
38
- .sidebar_title {
39
- font-size: 1.85em;
40
- line-height: 1.1;
41
- font-family:
42
- -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
43
- Arial, "Noto Sans", sans-serif;
44
- font-weight: 700;
45
- margin: 0;
46
- text-align: center;
47
- }
48
-
49
- .sidebar_description {
50
- font-size: small;
51
- margin: 0.5rem 0 0;
52
- text-align: center;
53
- }
54
-
55
- .sidebar_description a {
56
- text-decoration: none;
57
- border-bottom: 2px solid var(--sidebar-border);
58
- color: var(--sidebar-link);
59
- margin: 0;
60
- }