File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -270,12 +270,19 @@ Should return object which includes custom options for [request](https://github.
270270If multiple actions ` beforeRequest ` added - scraper will use ` requestOptions ` from last one.
271271``` javascript
272272// Add ?myParam=123 to querystring for resource with url 'http://example.com'
273- registerAction (' beforeRequest' , ({resource, requestOptions}) => {
273+ registerAction (' beforeRequest' , async ({resource, requestOptions}) => {
274274 if (resource .getUrl () === ' http://example.com' ) {
275275 return {requestOptions: extend (requestOptions, {qs: {myParam: 123 }})};
276276 }
277277 return {requestOptions};
278278});
279+
280+ // Server rejecting a scrape attempt, simply add in some synthetic delays
281+ registerAction (' beforeRequest' , async ({ resource, requestOptions }) => {
282+ const time = Math .round (Math .random () * 10000 );
283+ await new Promise ((resolve ) => setTimeout (resolve, time));
284+ return { requestOptions };
285+ });
279286```
280287
281288##### afterResponse
You can’t perform that action at this time.
0 commit comments