Skip to content

Commit 081ef1f

Browse files
gregbergeclaude
andcommitted
Drop page-context scope from docs; document webframe navigate
Per review, the current page is exposed to webframes without a dedicated scope, so remove site:page:context from the scopes list and reword the interactivity and reference docs (page is always available; visitor claims still need site:visitor:claims). Also document the @webframe.navigate action for navigating to another page in the site. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 63977a2 commit 081ef1f

4 files changed

Lines changed: 39 additions & 12 deletions

File tree

docs/integrations/configurations.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ The scopes your integration has permissions for.
9999
- site:script:cookies ## Internal scope - see note below
100100
- site:visitor:auth ## Enable workflows related to authenticated access
101101
- site:visitor:claims ## Expose visitor claims to webframes
102-
- site:page:context ## Expose the current page (id, path, title) to webframes
103102
- site:adaptive:read ## Read claims available from Adaptive Content
104103
- site:adaptive:write ## Write claims avaiable to Adaptive Content
105104
# OpenAPI

docs/integrations/contentkit/interactivity.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,26 +93,40 @@ window.addEventListener("message", (event) => {
9393

9494
## Page and visitor context
9595

96-
In addition to the values you bind through the `data` prop, GitBook injects contextual information about the current site into the webframe `state`, as long as your integration requests the matching [scope](../configurations.md#scopes):
96+
GitBook injects contextual information about the current site into the webframe `state`, alongside the values you bind through the `data` prop:
9797

98-
- `state.page` — the current page as `{ id, path, title }`, when the integration has the `site:page:context` scope.
99-
- `state.visitor` — the visitor claims, when the integration has the `site:visitor:claims` scope.
98+
- `state.page` — the current page as `{ id, path, title }`. Always available.
99+
- `state.visitor` — the visitor claims, when the integration has the `site:visitor:claims` [scope](../configurations.md#scopes).
100100

101-
This context is delivered client-side through the same `message` event as your bound `data`, so requesting it does not change how the integration block is cached:
101+
This context is delivered client-side through the same `message` event as your bound `data`, so it does not change how the integration block is cached:
102102

103103
```js
104104
window.addEventListener("message", (event) => {
105105
const state = event.data?.state;
106106
if (!state) return;
107107

108-
// Current page — only present when the integration has the `site:page:context` scope.
109108
if (state.page) {
110109
const { id, path, title } = state.page;
111110
// e.g. build a link to a sibling page from `path`
112111
}
113112
});
114113
```
115114
115+
## Navigating to another page
116+
117+
A webframe can navigate the reader to another page in the site by posting a `@webframe.navigate` action with the target page `path` (the same format as `state.page.path`):
118+
119+
```js
120+
window.parent.postMessage({
121+
action: {
122+
action: '@webframe.navigate',
123+
path: 'guides/getting-started',
124+
},
125+
}, '*');
126+
```
127+
128+
GitBook resolves the path within the current space, so navigation always stays inside the site.
129+
116130
## Webframes and actions
117131
118132
Webframes are powerful elements to integrate in GitBook external applications or complete UI. Passing data to the webframe can be done using the `data` prop. But the webframe also needs to be able to communicate data back to the top component. It can be achieved using the `window.postMessage`:

docs/integrations/development/contentkit/reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ If you need a copy button, only add it when your integration has a supported way
264264
| `buttons` | `Array<Button>` | Overlay buttons |
265265
| `data` | `Record<string, string>` | State dependencies |
266266

267-
The `data` values, together with GitBook-provided context, reach the frame through the `message` event as `event.data.state`. GitBook reserves two keys in `state`: `page` (`{ id, path, title }` of the current page, with the `site:page:context` scope) and `visitor` (visitor claims, with the `site:visitor:claims` scope). See [Interactivity](../../contentkit/interactivity.md#page-and-visitor-context).
267+
The `data` values, together with GitBook-provided context, reach the frame through the `message` event as `event.data.state`. GitBook reserves two keys in `state`: `page` (`{ id, path, title }` of the current page, always available) and `visitor` (visitor claims, with the `site:visitor:claims` scope). A webframe can also navigate the reader to another page by posting a `@webframe.navigate` action. See [Interactivity](../../contentkit/interactivity.md#page-and-visitor-context).
268268

269269
#### `select`
270270

docs/integrations/guides/interactivity.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,26 +97,40 @@ window.addEventListener("message", (event) => {
9797

9898
### Page and visitor context
9999

100-
In addition to the values you bind through the `data` prop, GitBook injects contextual information about the current site into the webframe `state`, as long as your integration requests the matching [scope](../configurations.md#scopes):
100+
GitBook injects contextual information about the current site into the webframe `state`, alongside the values you bind through the `data` prop:
101101

102-
- `state.page` — the current page as `{ id, path, title }`, when the integration has the `site:page:context` scope.
103-
- `state.visitor` — the visitor claims, when the integration has the `site:visitor:claims` scope.
102+
- `state.page` — the current page as `{ id, path, title }`. Always available.
103+
- `state.visitor` — the visitor claims, when the integration has the `site:visitor:claims` [scope](../configurations.md#scopes).
104104

105-
This context is delivered client-side through the same `message` event as your bound `data`, so requesting it does not change how the integration block is cached:
105+
This context is delivered client-side through the same `message` event as your bound `data`, so it does not change how the integration block is cached:
106106

107107
```js
108108
window.addEventListener("message", (event) => {
109109
const state = event.data?.state;
110110
if (!state) return;
111111

112-
// Current page — only present when the integration has the `site:page:context` scope.
113112
if (state.page) {
114113
const { id, path, title } = state.page;
115114
// e.g. build a link to a sibling page from `path`
116115
}
117116
});
118117
```
119118
119+
### Navigating to another page
120+
121+
A webframe can navigate the reader to another page in the site by posting a `@webframe.navigate` action with the target page `path` (the same format as `state.page.path`):
122+
123+
```js
124+
window.parent.postMessage({
125+
action: {
126+
action: '@webframe.navigate',
127+
path: 'guides/getting-started',
128+
},
129+
}, '*');
130+
```
131+
132+
GitBook resolves the path within the current space, so navigation always stays inside the site.
133+
120134
### Editable blocks
121135
122136
Some blocks might be static or only generated from link unfurling, but most blocks are designed to be editable by the user. Editable means that the user can interact with the blocks to change its properties.

0 commit comments

Comments
 (0)