Skip to content

Commit

Permalink
feat(core): user profile locale, tz, geo, viewport
Browse files Browse the repository at this point in the history
  • Loading branch information
blakebyrnes committed Jul 17, 2023
1 parent 8e34a42 commit 88e59c9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
8 changes: 8 additions & 0 deletions core/lib/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,13 +563,21 @@ export default class Session
userAgentSelector: userAgent ?? userProfile?.userAgentString,
};

if (userProfile) {
options.locale ??= userProfile.locale;
options.timezoneId ??= userProfile.timezoneId;
options.geolocation ??= userProfile.geolocation;
options.viewport ??= userProfile.deviceProfile?.viewport;
}

this.agent = this.core.pool.createAgent({
options,
customEmulatorConfig,
logger: this.logger,
deviceProfile: userProfile?.deviceProfile,
id: this.id,
commandMarker: this.commands,
userAgentOption: userProfile?.userAgent,
});

this.plugins = new CorePlugins(
Expand Down
8 changes: 6 additions & 2 deletions core/lib/UserProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@ export default class UserProfile {
}
}

return {
return <IUserProfile>{
cookies,
storage: exportedStorage,
geolocation: session.emulationProfile.geolocation,
locale: session.emulationProfile.locale,
timezoneId: session.emulationProfile.timezoneId,
userAgent: session.emulationProfile.userAgentOption,
userAgentString: session.emulationProfile.userAgentOption.string,
deviceProfile: session.emulationProfile.deviceProfile,
} as IUserProfile;
};
}

public static async installCookies(session: Session): Promise<UserProfile> {
Expand Down
9 changes: 8 additions & 1 deletion interfaces/IUserProfile.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { ICookie } from '@ulixee/unblocked-specification/agent/net/ICookie';
import IDomStorage from '@ulixee/unblocked-specification/agent/browser/IDomStorage';
import { ICookie } from '@ulixee/unblocked-specification/agent/net/ICookie';
import IDeviceProfile from '@ulixee/unblocked-specification/plugin/IDeviceProfile';
import IGeolocation from '@ulixee/unblocked-specification/plugin/IGeolocation';
import IUserAgentOption from '@ulixee/unblocked-specification/plugin/IUserAgentOption';

export default interface IUserProfile {
cookies?: ICookie[];
storage?: IDomStorage;
userAgentString?: string;
userAgent?: IUserAgentOption;
// need actual user agent details...
timezoneId?: string;
locale?: string;
geolocation?: IGeolocation;
deviceProfile?: IDeviceProfile;
}

0 comments on commit 88e59c9

Please sign in to comment.