@@ -55,7 +55,10 @@ const client = new Kernel({
5555});
5656
5757async function main() {
58- const params: Kernel .BrowserCreateParams = { invocation_id: ' REPLACE_ME' };
58+ const params: Kernel .BrowserCreateParams = {
59+ invocation_id: ' REPLACE_ME' ,
60+ persistence: { id: ' browser-for-user-1234' },
61+ };
5962 const browser: Kernel .BrowserCreateResponse = await client .browsers .create (params );
6063}
6164
@@ -117,15 +120,17 @@ a subclass of `APIError` will be thrown:
117120<!-- prettier-ignore -->
118121``` ts
119122async function main() {
120- const browser = await client .browsers .create ({ invocation_id: ' REPLACE_ME' }).catch (async (err ) => {
121- if (err instanceof Kernel .APIError ) {
122- console .log (err .status ); // 400
123- console .log (err .name ); // BadRequestError
124- console .log (err .headers ); // {server: 'nginx', ...}
125- } else {
126- throw err ;
127- }
128- });
123+ const browser = await client .browsers
124+ .create ({ invocation_id: ' REPLACE_ME' , persistence: { id: ' browser-for-user-1234' } })
125+ .catch (async (err ) => {
126+ if (err instanceof Kernel .APIError ) {
127+ console .log (err .status ); // 400
128+ console .log (err .name ); // BadRequestError
129+ console .log (err .headers ); // {server: 'nginx', ...}
130+ } else {
131+ throw err ;
132+ }
133+ });
129134}
130135
131136main ();
@@ -160,7 +165,7 @@ const client = new Kernel({
160165});
161166
162167// Or, configure per-request:
163- await client .browsers .create ({ invocation_id: ' REPLACE_ME' }, {
168+ await client .browsers .create ({ invocation_id: ' REPLACE_ME' , persistence : { id : ' browser-for-user-1234 ' } }, {
164169 maxRetries: 5 ,
165170});
166171```
@@ -177,7 +182,7 @@ const client = new Kernel({
177182});
178183
179184// Override per-request:
180- await client .browsers .create ({ invocation_id: ' REPLACE_ME' }, {
185+ await client .browsers .create ({ invocation_id: ' REPLACE_ME' , persistence: { id: ' browser-for-user-1234 ' } }, {
181186 timeout: 5 * 1000 ,
182187});
183188```
@@ -200,12 +205,14 @@ Unlike `.asResponse()` this method consumes the body, returning once it is parse
200205``` ts
201206const client = new Kernel ();
202207
203- const response = await client .browsers .create ({ invocation_id: ' REPLACE_ME' }).asResponse ();
208+ const response = await client .browsers
209+ .create ({ invocation_id: ' REPLACE_ME' , persistence: { id: ' browser-for-user-1234' } })
210+ .asResponse ();
204211console .log (response .headers .get (' X-My-Header' ));
205212console .log (response .statusText ); // access the underlying Response object
206213
207214const { data : browser, response : raw } = await client .browsers
208- .create ({ invocation_id: ' REPLACE_ME' })
215+ .create ({ invocation_id: ' REPLACE_ME' , persistence: { id: ' browser-for-user-1234 ' } })
209216 .withResponse ();
210217console .log (raw .headers .get (' X-My-Header' ));
211218console .log (browser .session_id );
0 commit comments