Skip to content

Commit

Permalink
feat(blockedResourceUrls): expose and document
Browse files Browse the repository at this point in the history
  • Loading branch information
glendc committed Nov 8, 2022
1 parent 76c5c45 commit 2db8b93
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions client/interfaces/IHeroDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import IUserProfile from '@ulixee/hero-interfaces/IUserProfile';

export default interface IHeroDefaults {
defaultBlockedResourceTypes?: IBlockedResourceType[];
defaultBlockedResourceUrls?: string[];
defaultUserProfile?: IUserProfile;
}
2 changes: 2 additions & 0 deletions client/lib/Hero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import { IDomExtensionClass, isDomExtensionClass } from './DomExtender';

export const DefaultOptions = {
defaultBlockedResourceTypes: [BlockedResourceType.None],
defaultBlockedResourceUrls: [],
defaultUserProfile: {},
};

Expand Down Expand Up @@ -118,6 +119,7 @@ export default class Hero extends AwaitedEventTarget<{

const { name, connectionToCore, ...options } = createOptions;
options.blockedResourceTypes ??= Hero.options.defaultBlockedResourceTypes;
options.blockedResourceUrls ??= Hero.options.defaultBlockedResourceUrls;
options.userProfile ??= Hero.options.defaultUserProfile;

const sessionName = scriptInstance.generateSessionName(name);
Expand Down
5 changes: 4 additions & 1 deletion core/lib/Tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,10 @@ export default class Tab
private async waitForReady(): Promise<void> {
await this.mainFrameEnvironment.isReady;
if (this.session.options?.blockedResourceTypes) {
await this.setBlockedResourceTypes(this.session.options.blockedResourceTypes);
await this.setBlockedResourceTypes(
this.session.options.blockedResourceTypes,
this.session.options.blockedResourceUrls,
);
}
}

Expand Down
2 changes: 2 additions & 0 deletions docs/main/BasicClient/Hero.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const Hero = require('@ulixee/hero-playground');
- positionX? `number`. Optional override browser X position on screen in pixels (minimum 0, maximum 10000000).
- positionY? `number`. Optional override browser Y position on screen in pixels (minimum 0, maximum 10000000).
- blockedResourceTypes `BlockedResourceType[]`. Controls browser resource loading. Valid options are listed [here](/docs/hero/overview/configuration#blocked-resources).
- blockedResourceUrls: `string[]`. Also controls browser resource loading. See for morei nformation [here](/docs/hero/overview/configuration#blocked-urls).
- showChrome `boolean`. A boolean whether to show the Chrome browser window. Can also be set with an env variable: `ULX_SHOW_CHROME=true`. Default `false`.
- showChromeInteractions `boolean`. A boolean whether to inject user interactions to mimic headless mouse/keyboard activity. Default `false`.
- showChromeAlive `boolean`. A boolean whether to show the ChromeAlive! toolbar (if installed in devDependencies, or using Ulixee.app). Default `false`.
Expand Down Expand Up @@ -185,6 +186,7 @@ Retrieves metadata about the hero configuration:
- geolocation `IGeolocation`. The configured geolocation of the user (if set).
- viewport `IViewport`. The emulated viewport size and location.
- blockedResourceTypes `BlockedResourceType[]`. The blocked resource types.
- blockedResourceUrls `string[]`. The blocked urls.
- upstreamProxyUrl `string`. The proxy url in use for this hero.
- upstreamProxyIpMask `object`. The proxy IP mask settings for this hero.
- ipLookupService `string`. Lookup service used to find public IP.
Expand Down
3 changes: 3 additions & 0 deletions docs/main/Overview/BasicConcepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ await hero.goto('https://ulixee.org');
const doc = await hero.fetch('https://ulixee.org/docs/overview/configuration');
```

Next to `blockedResourceTypes` you can also use `blockedResourceUrls`,
see [here](/docs/overview/configuration#blocked-urls) for more information.

## Mice and Keyboards Are Human Too

Hero drives mice and keyboards with [Human Emulators](/docs/hero/plugins/human-emulators). Human emulators translate your clicks and moves into randomized human-like patterns that can pass bot-blocker checks.
16 changes: 16 additions & 0 deletions docs/main/Overview/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ As you'll notice above, some features are dependent on others and therefore auto

Setting an empty array is the same as setting to `None`.

### Blocked Urls<div class="specs"><i>Connection</i><i>Hero</i></div> {#blocked-urls}

Similar to [`Blocked Resource Types`](#blocked-resources), this allows you to block resources
from being loaded. Instead of focussing on the type of resource we are focussing on the url instead.

Wild cards can be used as well.

Examples:

```
http://example.com
example.com
*.example.com
*example.com
```

### User Profile <div class="specs"><i>Connection</i><i>Hero</i></div>

A user profile stores and restores Cookies, DOM Storage and IndexedDB records for an Hero. NOTE: the serialized user profile passed into an Hero instance is never modified. If you want to update a profile with changes, you should re-export and save it to the format you're persisting to.
Expand Down
1 change: 1 addition & 0 deletions interfaces/IConfigureSessionOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export default interface IConfigureSessionOptions
| 'locale'
| 'upstreamProxyUrl'
| 'blockedResourceTypes'
| 'blockedResourceUrls'
> {}
1 change: 1 addition & 0 deletions interfaces/ITabOptions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export default interface ITabOptions {
blockedResourceTypes?: IBlockedResourceType[];
blockedResourceUrls?: string[];
}

export enum BlockedResourceType {
Expand Down

0 comments on commit 2db8b93

Please sign in to comment.