@@ -26,7 +26,9 @@ const client = new BrowserUse({
26
26
apiKey: process .env [' BROWSER_USE_API_KEY' ], // This is the default and can be omitted
27
27
});
28
28
29
- const task = await client .tasks .create ({ task: ' x' });
29
+ const task = await client .tasks .create ({
30
+ task: ' Search for the top 10 Hacker News posts and return the title and url.' ,
31
+ });
30
32
31
33
console .log (task .id );
32
34
```
@@ -43,7 +45,9 @@ const client = new BrowserUse({
43
45
apiKey: process .env [' BROWSER_USE_API_KEY' ], // This is the default and can be omitted
44
46
});
45
47
46
- const params: BrowserUse .TaskCreateParams = { task: ' x' };
48
+ const params: BrowserUse .TaskCreateParams = {
49
+ task: ' Search for the top 10 Hacker News posts and return the title and url.' ,
50
+ };
47
51
const task: BrowserUse .TaskCreateResponse = await client .tasks .create (params );
48
52
```
49
53
@@ -57,15 +61,17 @@ a subclass of `APIError` will be thrown:
57
61
58
62
<!-- prettier-ignore -->
59
63
``` ts
60
- const task = await client .tasks .create ({ task: ' x' }).catch (async (err ) => {
61
- if (err instanceof BrowserUse .APIError ) {
62
- console .log (err .status ); // 400
63
- console .log (err .name ); // BadRequestError
64
- console .log (err .headers ); // {server: 'nginx', ...}
65
- } else {
66
- throw err ;
67
- }
68
- });
64
+ const task = await client .tasks
65
+ .create ({ task: ' Search for the top 10 Hacker News posts and return the title and url.' })
66
+ .catch (async (err ) => {
67
+ if (err instanceof BrowserUse .APIError ) {
68
+ console .log (err .status ); // 400
69
+ console .log (err .name ); // BadRequestError
70
+ console .log (err .headers ); // {server: 'nginx', ...}
71
+ } else {
72
+ throw err ;
73
+ }
74
+ });
69
75
```
70
76
71
77
Error codes are as follows:
@@ -97,7 +103,7 @@ const client = new BrowserUse({
97
103
});
98
104
99
105
// Or, configure per-request:
100
- await client .tasks .create ({ task: ' x ' }, {
106
+ await client .tasks .create ({ task: ' Search for the top 10 Hacker News posts and return the title and url. ' }, {
101
107
maxRetries: 5 ,
102
108
});
103
109
```
@@ -114,7 +120,7 @@ const client = new BrowserUse({
114
120
});
115
121
116
122
// Override per-request:
117
- await client .tasks .create ({ task: ' x ' }, {
123
+ await client .tasks .create ({ task: ' Search for the top 10 Hacker News posts and return the title and url. ' }, {
118
124
timeout: 5 * 1000 ,
119
125
});
120
126
```
@@ -137,11 +143,15 @@ Unlike `.asResponse()` this method consumes the body, returning once it is parse
137
143
``` ts
138
144
const client = new BrowserUse ();
139
145
140
- const response = await client .tasks .create ({ task: ' x' }).asResponse ();
146
+ const response = await client .tasks
147
+ .create ({ task: ' Search for the top 10 Hacker News posts and return the title and url.' })
148
+ .asResponse ();
141
149
console .log (response .headers .get (' X-My-Header' ));
142
150
console .log (response .statusText ); // access the underlying Response object
143
151
144
- const { data : task, response : raw } = await client .tasks .create ({ task: ' x' }).withResponse ();
152
+ const { data : task, response : raw } = await client .tasks
153
+ .create ({ task: ' Search for the top 10 Hacker News posts and return the title and url.' })
154
+ .withResponse ();
145
155
console .log (raw .headers .get (' X-My-Header' ));
146
156
console .log (task .id );
147
157
```
0 commit comments