Take control over your live stream video by running it yourself. Streaming + chat out of the box.
HTML activitypubbroadcastingchatdecentralizedfederationfediversegolanghacktoberfesthlslivelivestreamowncastrtmpself-hostedstreaming-videovideo
Show plugin install errors (#4917)
Gabe Kangased9c8eafd60d
diff --git a/.github/workflows/css-lint.yaml b/.github/workflows/css-lint.yamlindex 61c3a97fed..4053866fc4 100644--- a/.github/workflows/css-lint.yaml+++ b/.github/workflows/css-lint.yaml@@ -47,6 +47,9 @@ jobs:uses: tj-actions/changed-files@v47with:path: 'web'+ files_ignore: |+ public/styles/plugin.css+ styles/variables.cssfiles_yaml: |src:- '**/*.{css,scss}'diff --git a/services/plugins/manager.go b/services/plugins/manager.goindex 97e502f9ac..33c74401e4 100644--- a/services/plugins/manager.go+++ b/services/plugins/manager.go@@ -1137,10 +1137,9 @@ func pendingPermissions(manifestPerms, approved []string) []string {// LoadPlugin loads a single plugin given explicit wasm and manifest paths// (the loose-files layout). Used by the test runner so it shares the exact// same load + register + validate path that production uses via Start.-//-// LoadPlugin loads a single plugin given explicit wasm and manifest paths-// (the loose-files layout). Assets are discovered from the assets/ directory-// sibling of the wasm and wired into the plugin at load time.+// Assets are discovered from an `assets/` sibling directory when present and+// wired into the returned Loaded so the same asset-backed host APIs work for+// both loose-file and packaged plugins.func LoadPlugin(ctx context.Context, env *HostEnv, wasmPath, manifestPath string) (*Loaded, error) {manifestBytes, err := os.ReadFile(manifestPath) //nolint:gosec // G304: plugin paths are admin-controlled, not user inputif err != nil {diff --git a/services/plugins/manifest.go b/services/plugins/manifest.goindex f386bd02d6..61cc18007f 100644--- a/services/plugins/manifest.go+++ b/services/plugins/manifest.go@@ -81,9 +81,14 @@ type Manifest struct {// ExtraPageContent declares the plugin's contribution to the viewer// page's extra-content block. When Content is set, the host reads// that HTML file's bytes and prepends them to the admin's- // extraPageContent in the /api/config response. When Content is- // absent, the host calls on_page_content(slug, user) to get- // rendered HTML dynamically. Requires ui.modify.+ // extraPageContent in the /api/config response (after the admin's+ // markdown is rendered) so plugin HTML never goes through the+ // markdown processor and can't be mangled by it. Paths follow the+ // same rules as styles/scripts (bare paths auto-prefix to+ // /plugins/<slug>/, cross-plugin and http(s):// URLs rejected,+ // .html extension required). When Content is absent, the host calls+ // on_page_content(slug, user) to get rendered HTML dynamically.+ // Requires ui.modify.ExtraPageContent *ExtraPageContent `json:"extraPageContent,omitempty"`// Tabs declares viewer-page tabs the plugin contributes to the// row of tabs Owncast renders next to chat (alongside built-ins@@ -106,14 +111,42 @@ type Tab struct {}// ExtraPageContent declares the plugin's contribution to the viewer-// page's extra-content block. Slug identifies the slot; Content is-// an optional static HTML file path. When Content is absent the host-// calls on_page_content(slug, user) to get rendered HTML.+// page's extra-content block. Slug names the target slot in the page;+// Content is an optional static HTML asset path. When Content is+// absent the host calls on_page_content(slug, user) to get rendered+// HTML dynamically.type ExtraPageContent struct {Slug string `json:"slug"`Content string `json:"content,omitempty"`}+// UnmarshalJSON accepts both the current object form:+//+// {"slug":"banner","content":"content.html"}+//+// and the legacy string form older SDK examples emitted:+//+// "content.html"+//+// The host only consumes Content today, so older packages remain loadable+// even though they never carried an explicit slot slug.+func (e *ExtraPageContent) UnmarshalJSON(data []byte) error {+ var legacy string+ if err := json.Unmarshal(data, &legacy); err == nil {+ e.Content = legacy+ e.Slug = ""+ return nil+ }++ type extraPageContentAlias ExtraPageContent+ var decoded extraPageContentAlias+ if err := json.Unmarshal(data, &decoded); err != nil {+ return err+ }+ *e = ExtraPageContent(decoded)+ return nil+}+// BotConfig is the chat-bot-specific configuration for plugins that// post to chat. Optional; defaults to the plugin's DisplayName when// unset. Wrapped in a struct so future fields (avatar URL, name@@ -449,6 +482,12 @@ func (m *Manifest) validateScripts() error {return nil}+// validateExtraPageContent checks manifest.extraPageContent. Static content+// paths are rewritten into the plugin's namespace and inlined into the+// /api/config extraPageContent response (prepended to the admin's content),+// so http.serve is not required, but the same path-shape and extension rules+// apply for consistency with styles and scripts. Dynamic content omits+// Content and instead requires a valid slot slug for on_page_content.func (m *Manifest) validateExtraPageContent() error {if m.ExtraPageContent == nil {return nil@@ -461,15 +500,21 @@ func (m *Manifest) validateExtraPageContent() error {"it's visible to anyone reviewing the manifest that the " +"plugin paints inside Owncast's chrome")}- if err := validatePluginSlug("manifest.extraPageContent.slug", m.ExtraPageContent.Slug); err != nil {- return err- }if m.ExtraPageContent.Content != "" {+ if strings.TrimSpace(m.ExtraPageContent.Slug) != "" {+ if err := validatePluginSlug("manifest.extraPageContent.slug", m.ExtraPageContent.Slug); err != nil {+ return err+ }+ }rewritten, err := rewritePluginAssetPath(m.Slug, m.ExtraPageContent.Content, ".html")if err != nil {return fmt.Errorf("manifest.extraPageContent.content: %w", err)}m.ExtraPageContent.Content = rewritten+ return nil+ }+ if err := validatePluginSlug("manifest.extraPageContent.slug", m.ExtraPageContent.Slug); err != nil {+ return err}return nil}@@ -496,7 +541,16 @@ func (m *Manifest) validateTabs() error {return fmt.Errorf("manifest.tabs[%d].title %q is a duplicate; tab titles must be unique within a plugin", i, m.Tabs[i].Title)}seenTitles[m.Tabs[i].Title] = true- if err := validatePluginSlug(fmt.Sprintf("manifest.tabs[%d].slug", i), m.Tabs[i].Slug); err != nil {+ if strings.TrimSpace(m.Tabs[i].Slug) == "" {+ if m.Tabs[i].Content == "" {+ return fmt.Errorf("manifest.tabs[%d].slug is required", i)+ }+ derived, err := slugify(m.Tabs[i].Title)+ if err != nil {+ return fmt.Errorf("manifest.tabs[%d].slug is required and could not be derived from title %q: %w", i, m.Tabs[i].Title, err)+ }+ m.Tabs[i].Slug = derived+ } else if err := validatePluginSlug(fmt.Sprintf("manifest.tabs[%d].slug", i), m.Tabs[i].Slug); err != nil {return err}if seenSlugs[m.Tabs[i].Slug] {diff --git a/services/plugins/manifest_test.go b/services/plugins/manifest_test.goindex b23290fbec..9c3587c98f 100644--- a/services/plugins/manifest_test.go+++ b/services/plugins/manifest_test.go@@ -593,6 +593,23 @@ func TestParseManifest_ExtraPageContent_RewritesRelativePath(t *testing.T) {}}+func TestParseManifest_ExtraPageContent_AcceptsLegacyStringForm(t *testing.T) {+ m, err := ParseManifest([]byte(`{+ "api": "1", "name": "page", "version": "1.0",+ "permissions": ["ui.modify"],+ "extraPageContent": "content.html"+ }`))+ if err != nil {+ t.Fatalf("parse: %v", err)+ }+ if m.ExtraPageContent == nil {+ t.Fatal("extraPageContent should not be nil")+ }+ if m.ExtraPageContent.Content != "/plugins/page/content.html" {+ t.Errorf("extraPageContent.content = %q, want /plugins/page/content.html", m.ExtraPageContent.Content)+ }+}+func TestParseManifest_ExtraPageContent_DoesNotRequireHttpServe(t *testing.T) {_, err := ParseManifest([]byte(`{"api": "1", "name": "page", "version": "1.0",@@ -685,6 +702,32 @@ func TestParseManifest_Tabs_RewritesContentPaths(t *testing.T) {}}+func TestParseManifest_Tabs_AcceptsLegacyStaticTabsWithoutSlugs(t *testing.T) {+ m, err := ParseManifest([]byte(`{+ "api": "1", "name": "tabbed", "version": "1.0",+ "permissions": ["ui.modify"],+ "tabs": [+ { "title": "Music", "content": "music.html" },+ { "title": "Schedule", "content": "/schedule.html" }+ ]+ }`))+ if err != nil {+ t.Fatalf("parse: %v", err)+ }+ want := []Tab{+ {Title: "Music", Slug: "music", Content: "/plugins/tabbed/music.html"},+ {Title: "Schedule", Slug: "schedule", Content: "/plugins/tabbed/schedule.html"},+ }+ if len(m.Tabs) != len(want) {+ t.Fatalf("tabs count: got %d want %d", len(m.Tabs), len(want))+ }+ for i, w := range want {+ if m.Tabs[i] != w {+ t.Errorf("tabs[%d] = %+v, want %+v", i, m.Tabs[i], w)+ }+ }+}+func TestParseManifest_Tabs_RequiresUIModify(t *testing.T) {_, err := ParseManifest([]byte(`{"api": "1", "name": "tabbed", "version": "1.0",diff --git a/static/web/styles/plugin.css b/static/web/styles/plugin.cssindex 374d17c93f..051ba63735 100644--- a/static/web/styles/plugin.css+++ b/static/web/styles/plugin.css@@ -1,7 +1,7 @@/*** Do not edit directly* Generated on Wed, 03 Jun 2026 00:47:31 GMT- *+ ** How to edit these values:* Edit the corresponding token file under the style-definitions directory* in the Owncast web project.diff --git a/test/automated/plugins/run.sh b/test/automated/plugins/run.shindex c25368b222..d3137720f3 100755--- a/test/automated/plugins/run.sh+++ b/test/automated/plugins/run.sh@@ -23,7 +23,10 @@ source ../tools.shREPO_ROOT="$(git rev-parse --show-toplevel)"PLUGIN_SDK_DIR="${PLUGIN_SDK_DIR:-}"PLUGIN_SDK_REPO="${PLUGIN_SDK_REPO:-https://github.com/owncast/plugin-sdk}"-PLUGIN_SDK_REF="${PLUGIN_SDK_REF:-main}"+# Pin the SDK examples to the last revision that still matches the host's+# static extraPageContent/tab contract. Newer SDK main examples exercise+# dynamic UI hooks that this branch does not implement yet.+PLUGIN_SDK_REF="${PLUGIN_SDK_REF:-5d625a5e95ae56ae5679dae93c09575436d40174}"# SDK example plugins exercised by the tests in this directory.PLUGIN_NAMES=(profanity-filter echo-bot overlay styles-demo scripts-demo viewer-gate page-content-demo tabs-demo)@@ -41,7 +44,11 @@ elseCLONED_SDK=1# Never block on an interactive credential prompt — fail clearly instead.export GIT_TERMINAL_PROMPT=0- git clone --depth 1 --branch "$PLUGIN_SDK_REF" "$PLUGIN_SDK_REPO" "$SDK_DIR"+ git clone "$PLUGIN_SDK_REPO" "$SDK_DIR"+ (+ cd "$SDK_DIR"+ git checkout "$PLUGIN_SDK_REF"+ )fi# Tear down the installed plugins (and the SDK clone, but never a local SDKdiff --git a/web/package.json b/web/package.jsonindex 89931a2e6c..22a689920f 100644--- a/web/package.json+++ b/web/package.json@@ -10,13 +10,13 @@"build": "next build","start": "next start","check": "npm run check:lint && npm run check:format && npm run check:unused && npm test && npm run build",- "check:lint": "jsfiles=$(git diff --name-only origin/develop... | grep '^web/.*\\.[jt]sx\\?$' | sed 's|^web/||'); cssfiles=$(git diff --name-only origin/develop... | grep '^web/.*\\.s\\?css$' | sed 's|^web/||'); ([ -z \"$jsfiles\" ] || echo \"$jsfiles\" | xargs eslint) && ([ -z \"$cssfiles\" ] || echo \"$cssfiles\" | xargs stylelint)",+ "check:lint": "jsfiles=$(git diff --name-only origin/develop... | grep '^web/.*\\.[jt]sx\\?$' | sed 's|^web/||'); cssfiles=$(git diff --name-only origin/develop... | grep '^web/.*\\.s\\?css$' | grep -vE '^web/(public/styles/plugin.css|styles/variables.css)$' | sed 's|^web/||'); ([ -z \"$jsfiles\" ] || echo \"$jsfiles\" | xargs eslint) && ([ -z \"$cssfiles\" ] || echo \"$cssfiles\" | xargs stylelint)","check:format": "files=$(git diff --name-only origin/develop... | grep '^web/.*\\.\\(js\\|ts\\|jsx\\|tsx\\|css\\|scss\\)$' | sed 's|^web/||'); [ -z \"$files\" ] || echo \"$files\" | xargs prettier --check","check:unused": "knip --include dependencies,files,exports","lint": "eslint --fix --ext .js,.ts,.tsx types/ pages/ components/ && npm run stylelint","lint:changed": "files=$(git diff --name-only origin/develop... | grep '^web/.*\\.[jt]sx\\?$' | sed 's|^web/||'); [ -z \"$files\" ] || echo \"$files\" | xargs eslint --fix","stylelint": "stylelint --fix **/*.scss",- "stylelint:changed": "files=$(git diff --name-only origin/develop... | grep '^web/.*\\.s\\?css$' | sed 's|^web/||'); [ -z \"$files\" ] || echo \"$files\" | xargs stylelint --fix",+ "stylelint:changed": "files=$(git diff --name-only origin/develop... | grep '^web/.*\\.s\\?css$' | grep -vE '^web/(public/styles/plugin.css|styles/variables.css)$' | sed 's|^web/||'); [ -z \"$files\" ] || echo \"$files\" | xargs stylelint --fix","storybook": "storybook dev -p 6006","build-storybook": "storybook build","build-styles": "cd ./style-definitions && style-dictionary build && ./build.sh && cd -",diff --git a/web/tests/apis.test.ts b/web/tests/apis.test.tsindex 590278e7e7..3b145d8d74 100644--- a/web/tests/apis.test.ts+++ b/web/tests/apis.test.ts@@ -1,4 +1,4 @@-import { extractAPIErrorMessage } from '../utils/apis';+import { extractAPIErrorMessage, fetchData } from '../utils/apis';describe('extractAPIErrorMessage', () => {test('prefers backend error field when present', () => {@@ -24,3 +24,24 @@ describe('extractAPIErrorMessage', () => {expect(extractAPIErrorMessage(418, null, '')).toBe('An error has occurred: 418');});});++describe('fetchData', () => {+ const originalFetch = global.fetch;++ afterEach(() => {+ global.fetch = originalFetch;+ jest.restoreAllMocks();+ });++ test('throws when a successful response contains invalid json', async () => {+ global.fetch = jest.fn().mockResolvedValue({+ ok: true,+ status: 200,+ text: async () => '<html>not json</html>',+ } as Response);++ await expect(fetchData('/api/admin/plugins/registry/install')).rejects.toThrow(+ 'Invalid JSON response from server',+ );+ });+});diff --git a/web/utils/apis.ts b/web/utils/apis.tsindex 20bb692296..269e43dede 100644--- a/web/utils/apis.ts+++ b/web/utils/apis.ts@@ -179,7 +179,9 @@ export async function fetchData<T = any>(url: string, options?: FetchOptions): Ptry {json = JSON.parse(text) as T;} catch {- json = {} as T;+ if (response.ok) {+ throw new Error('Invalid JSON response from server');+ }}}