diff --git a/core/lib/Session.ts b/core/lib/Session.ts index c30d840c5..03fac303b 100644 --- a/core/lib/Session.ts +++ b/core/lib/Session.ts @@ -563,6 +563,13 @@ 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, @@ -570,6 +577,7 @@ export default class Session deviceProfile: userProfile?.deviceProfile, id: this.id, commandMarker: this.commands, + userAgentOption: userProfile?.userAgent, }); this.plugins = new CorePlugins( diff --git a/core/lib/UserProfile.ts b/core/lib/UserProfile.ts index c1129b106..73454667f 100644 --- a/core/lib/UserProfile.ts +++ b/core/lib/UserProfile.ts @@ -54,12 +54,16 @@ export default class UserProfile { } } - return { + return { 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 { diff --git a/interfaces/IUserProfile.ts b/interfaces/IUserProfile.ts index 019cd601d..2626f6d15 100644 --- a/interfaces/IUserProfile.ts +++ b/interfaces/IUserProfile.ts @@ -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; }