Skip to content

feat(types): execInPage, onRequest & party APIs + supports() capability helper#10933

Merged
Bas950 merged 9 commits into
mainfrom
feat/presence-execinpage-onrequest
Jun 26, 2026
Merged

feat(types): execInPage, onRequest & party APIs + supports() capability helper#10933
Bas950 merged 9 commits into
mainfrom
feat/presence-execinpage-onrequest

Conversation

@Timeraa

@Timeraa Timeraa commented Jun 24, 2026

Copy link
Copy Markdown
Member

What

Adds the activity-facing types and tooling for three new Presence/iFrame capabilities, plus a runtime feature-detection helper so activities can adopt them safely today.

  • execInPage — run a function (or a declarative, CSP-immune get/call spec) in the page's own context and await a returned value.
  • onRequest — read data out of page network requests via a URL/method filter (read-only, no modification).
  • party on PresenceData — show a party size on Playing activities (e.g. "2 of 5"); partyId optional, only honored on ActivityType.Playing.
  • supports(target, feature) — bundled into the activity, returns true when the running extension exposes the capability. Lets activities feature-detect instead of crashing on older installs.
  • ESLint rule — errors on unguarded execInPage/onRequest usage, with an autofix that wraps the call in a supports() check.

Versioning

These APIs ship with the extension in 2.14.0. They can be used as of right now: because supports() is compiled into the activity bundle, it detects the capability at runtime, so an activity guarded with supports() works on 2.14.0+ and degrades gracefully (no-op) on older extensions instead of throwing. The lint rule enforces that guard.

if (supports(presence, 'onRequest')) {
  presence.onRequest({ url: '/api/now-playing', method: 'GET' }, (req) => { /* ... */ })
}

@Timeraa Timeraa requested a review from Bas950 June 24, 2026 11:10
Comment thread @types/premid/index.d.ts Outdated
Comment thread @types/premid/index.d.ts Outdated
Type execInPage's rest args as a tuple generic (A extends unknown[]) so
the values passed are forwarded to the closure with their types instead
of erasing to unknown[]. Applies to both Presence and iFrame overloads.

Addresses review feedback on #10933.
@Bas950 Bas950 enabled auto-merge (squash) June 24, 2026 11:41
@Bas950 Bas950 requested a review from a team June 24, 2026 11:41
@Bas950 Bas950 added the repo maintenance General repo maintenance, including updating tools etc label Jun 24, 2026
@Timeraa Timeraa marked this pull request as draft June 24, 2026 21:52
auto-merge was automatically disabled June 24, 2026 21:52

Pull request was converted to draft

- presence-class (API + guide): detailed execInPage (function + declarative
  ExecInPageSpec forms) and onRequest (RequestFilter, InterceptedRequest,
  unsubscribe), both gated behind the supports() helper.
- presence-data: party / PartyData (only honored on ActivityType.Playing).
- utility-functions: supports() capability-detection helper.
- iframe: execInPage reference.

For #10933.
@Timeraa Timeraa marked this pull request as ready for review June 25, 2026 06:59
@Bas950 Bas950 requested a review from skullysmods June 25, 2026 22:14
Comment thread @types/premid/index.d.ts Outdated
Comment on lines +457 to +460
/** Only keep these top-level keys of the result. */
pick?: string[]
/** Drop these top-level keys from the result. */
omit?: string[]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can these be Dot-paths too?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call — done. pick/omit now accept dot-paths (not just top-level keys), matching get/call.

Runtime change in PreMiD/Extension#780: resolvePickOmit routes keys through dot-prop, so e.g. pick: ['track.name'] narrows a call result to { track: { name } } — which previously had no CSP-immune form (get can't invoke, top-level pick keeps the whole track). The filter runs on the serialized clone, so dot-path omit can't mutate page objects. Types + docs updated here in cac217e.

pick/omit accept dot-paths in the runtime (PreMiD/Extension#780); document
the nested-field capability on the type and in the API reference.
Comment thread docs/v1/api/presence-class.md Fixed
Comment thread docs/v1/api/presence-class.md Fixed
Comment thread docs/v1/api/presence-class.md Fixed
Comment thread docs/v1/api/presence-class.md Fixed
Comment thread docs/v1/api/presence-class.md Fixed
Comment thread docs/v1/api/presence-class.md Fixed
@Bas950 Bas950 merged commit 189fefc into main Jun 26, 2026
9 checks passed
@Bas950 Bas950 deleted the feat/presence-execinpage-onrequest branch June 26, 2026 22:57
Bas950 pushed a commit that referenced this pull request Jul 1, 2026
…10944)

* fix: query selector for video detection

* chore: remove console log

* feat(types): add execInPage and onRequest APIs to Presence/iFrame

* docs(types): document feature-detection for execInPage/onRequest on older extensions

* feat(premid): add supports() helper for version-safe capability detection

* feat(lint): error on unguarded execInPage/onRequest with autofix to wrap in supports() check

* feat(types): add party to PresenceData (2.14.0)

* fix(types): infer execInPage arg types into the page closure

Type execInPage's rest args as a tuple generic (A extends unknown[]) so
the values passed are forwarded to the closure with their types instead
of erasing to unknown[]. Applies to both Presence and iFrame overloads.

Addresses review feedback on #10933.

* feat(FACEIT): expand presence handling and user state detection

feat(i18n): add and refine localized FACEIT strings for browsing, matchroom, and party states

feat(party): add support for party states (189fefc)
feat(settings): update browsing and add elo, party info, and in-game presence title settings
fix(assets): switch elo rank 1-11 to better quality images
fix(queue): fix In Queue state not working

* feat(FACEIT): bump metadata version

* fix: resize icons from 38x38 to 512x512

* fix: party state if inviting a player

---------

Co-authored-by: Florian Metz <me@timeraa.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

repo maintenance General repo maintenance, including updating tools etc

Development

Successfully merging this pull request may close these issues.

4 participants