extension-create 4.0.3-canary.local-4f6380cc → 4.0.3

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.
@@ -0,0 +1,41 @@
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).
@@ -0,0 +1,19 @@
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
+ }
@@ -0,0 +1,32 @@
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": "latest"
25
+ },
26
+ "packageManager": "pnpm@10.28.0",
27
+ "pnpm": {
28
+ "ignoredBuiltDependencies": [
29
+ "less"
30
+ ]
31
+ }
32
+ }
@@ -0,0 +1,44 @@
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
+ chrome.action.onClicked.addListener(() => {
23
+ chrome.sidePanel.setPanelBehavior({openPanelOnActionClick: true})
24
+ })
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 && tabs[0] && 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
+ })
@@ -0,0 +1,42 @@
1
+ import iconUrl from '../images/icon.png'
2
+ const logo = iconUrl
3
+
4
+ export default function createContentApp() {
5
+ const container = document.createElement('div')
6
+ container.className = 'content_script'
7
+
8
+ const pill = document.createElement('button')
9
+ pill.type = 'button'
10
+ pill.className = 'content_pill'
11
+ pill.setAttribute('aria-label', 'Open sidebar')
12
+ pill.addEventListener('click', () => {
13
+ try {
14
+ if (
15
+ import.meta.env.EXTENSION_PUBLIC_BROWSER === 'firefox' ||
16
+ import.meta.env.EXTENSION_PUBLIC_BROWSER === 'gecko-based'
17
+ ) {
18
+ browser.runtime.sendMessage({type: 'openSidebar'})
19
+ } else {
20
+ chrome.runtime.sendMessage({type: 'openSidebar'})
21
+ }
22
+ } catch (error) {
23
+ console.error(error)
24
+ }
25
+ })
26
+
27
+ const img = document.createElement('img')
28
+ img.className = 'content_pill_logo'
29
+ img.src = logo
30
+ img.alt = ''
31
+ img.setAttribute('aria-hidden', 'true')
32
+
33
+ const text = document.createElement('span')
34
+ text.className = 'content_pill_text'
35
+ text.textContent = 'Open sidebar'
36
+
37
+ pill.appendChild(img)
38
+ pill.appendChild(text)
39
+ container.appendChild(pill)
40
+
41
+ return container
42
+ }
@@ -0,0 +1,38 @@
1
+ console.log('[From the page context] Hello from content_scripts!')
2
+ import createContentApp from './ContentApp.js'
3
+ import './styles.css'
4
+
5
+ /**
6
+ * Extension.js content_script entrypoint. The framework calls this on
7
+ * injection and calls the returned function on HMR/teardown to clean up.
8
+ * Do not invoke it yourself.
9
+ */
10
+ export default function initial() {
11
+ const rootDiv = document.createElement('div')
12
+ rootDiv.setAttribute('data-extension-root', 'true')
13
+ document.body.appendChild(rootDiv)
14
+
15
+ // Injecting content_scripts inside a shadow dom
16
+ // prevents conflicts with the host page's styles.
17
+ // This way, styles from the extension won't leak into the host page.
18
+ const shadowRoot = rootDiv.attachShadow({mode: 'open'})
19
+
20
+ const styleElement = document.createElement('style')
21
+ shadowRoot.appendChild(styleElement)
22
+ fetchCSS().then((response) => (styleElement.textContent = response))
23
+
24
+ // Render ContentApp inside shadow root
25
+ const container = createContentApp()
26
+ shadowRoot.appendChild(container)
27
+
28
+ return () => {
29
+ rootDiv.remove()
30
+ }
31
+ }
32
+
33
+ async function fetchCSS() {
34
+ const cssUrl = new URL('./styles.css', import.meta.url)
35
+ const response = await fetch(cssUrl)
36
+ const text = await response.text()
37
+ return response.ok ? text : Promise.reject(text)
38
+ }
@@ -0,0 +1,45 @@
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
+ }
@@ -0,0 +1,63 @@
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
+ "name": "test-template-javascript",
7
+ "description": "JavaScript-based extension with a sidebar panel. Adds a sidebar with a simple page.",
8
+ "icons": {
9
+ "16": "images/icon.png",
10
+ "32": "images/icon.png",
11
+ "48": "images/icon.png",
12
+ "64": "images/icon.png",
13
+ "128": "images/icon.png"
14
+ },
15
+ "chromium:action": {
16
+ "default_icon": {
17
+ "16": "images/icon.png",
18
+ "32": "images/icon.png",
19
+ "48": "images/icon.png",
20
+ "64": "images/icon.png",
21
+ "128": "images/icon.png"
22
+ },
23
+ "default_title": "Open Side Panel"
24
+ },
25
+ "firefox:browser_action": {
26
+ "default_icon": {
27
+ "16": "images/icon.png",
28
+ "32": "images/icon.png",
29
+ "48": "images/icon.png",
30
+ "64": "images/icon.png",
31
+ "128": "images/icon.png"
32
+ },
33
+ "default_title": "Open Side Panel"
34
+ },
35
+ "chromium:side_panel": {
36
+ "default_path": "sidebar/index.html",
37
+ "default_title": "Side Panel Content"
38
+ },
39
+ "firefox:sidebar_action": {
40
+ "default_panel": "sidebar/index.html",
41
+ "default_title": "Side Panel Content"
42
+ },
43
+ "chromium:permissions": [
44
+ "sidePanel"
45
+ ],
46
+ "background": {
47
+ "chromium:service_worker": "background.js",
48
+ "firefox:scripts": [
49
+ "background.js"
50
+ ]
51
+ },
52
+ "content_scripts": [
53
+ {
54
+ "matches": [
55
+ "<all_urls>"
56
+ ],
57
+ "js": [
58
+ "content/scripts.js"
59
+ ]
60
+ }
61
+ ],
62
+ "author": "Your Name"
63
+ }
@@ -0,0 +1,30 @@
1
+ import './styles.css'
2
+ import iconUrl from '../images/icon.png'
3
+
4
+ const javascriptLogo = iconUrl
5
+
6
+ function SidebarApp() {
7
+ const root = document.getElementById('root')
8
+ if (!root) return
9
+
10
+ root.innerHTML = `
11
+ <div class="sidebar_app">
12
+ <img
13
+ class="sidebar_logo"
14
+ src="${javascriptLogo}"
15
+ alt="The JavaScript logo"
16
+ />
17
+ <h1 class="sidebar_title">Sidebar Panel</h1>
18
+ <p class="sidebar_description">
19
+ Learn more in the
20
+ <a
21
+ href="https://extension.js.org"
22
+ target="_blank" rel="noopener noreferrer"
23
+ >Extension.js docs</a>
24
+ .
25
+ </p>
26
+ </div>
27
+ `
28
+ }
29
+
30
+ SidebarApp()
@@ -0,0 +1,13 @@
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>
@@ -0,0 +1,3 @@
1
+ console.log('[From the sidebar page context] Hello regular page!')
2
+ import './SidebarApp.js'
3
+ import './styles.css'
@@ -0,0 +1,60 @@
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
+ }
package/package.json CHANGED
@@ -25,7 +25,7 @@
25
25
  "templates"
26
26
  ],
27
27
  "name": "extension-create",
28
- "version": "4.0.3-canary.local-4f6380cc",
28
+ "version": "4.0.3",
29
29
  "description": "The standalone extension creation engine for Extension.js",
30
30
  "author": {
31
31
  "name": "Cezar Augusto",