@mearl/app-profiles 3.1.3 → 3.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/profiles.js +54 -15
  2. package/package.json +2 -2
package/dist/profiles.js CHANGED
@@ -184,10 +184,32 @@ export function buildAppProfileUa(profile, options = {}) {
184
184
  (options.devicePreset ? DEVICE_PRESETS[options.devicePreset]?.appProfileModel : undefined) ??
185
185
  'Pixel 11';
186
186
  if (profile.uaTemplate) {
187
- return profile.uaTemplate[os]
188
- .replaceAll('{v}', version)
189
- .replaceAll('{deviceModel}', deviceModel)
190
- .replaceAll('{language}', options.language ?? profile.policies?.defaultLanguage ?? 'zh-Hans');
187
+ let template = profile.uaTemplate[os];
188
+ const preset = options.devicePreset && DEVICE_PRESETS[options.devicePreset];
189
+ if (profile.uaFamily === 'device-webview' && preset && preset.appProfileOs === os) {
190
+ if (os === 'ios') {
191
+ const platform = preset.appProfileIosIdentity?.uaPlatform ??
192
+ /^Mozilla\/5\.0 \((iPhone; [^)]+)\)/.exec(preset.userAgent)?.[1];
193
+ const engine = /AppleWebKit\/[\d.]+/.exec(preset.userAgent)?.[0];
194
+ if (platform)
195
+ template = template.replace(/^(Mozilla\/5\.0 )\(i(?:Phone|Pad); [^)]+\)/, `$1(${platform})`);
196
+ if (engine)
197
+ template = template.replace(/AppleWebKit\/[\d.]+/, engine);
198
+ }
199
+ else if (preset.platform === 'Android') {
200
+ const chrome = /Chrome\/[\d.]+/.exec(preset.userAgent)?.[0];
201
+ template = template.replace(/\(Linux; Android [\d.]+;/, `(Linux; Android ${preset.platformVersion};`);
202
+ if (chrome)
203
+ template = template.replace(/Chrome\/[\d.]+/, chrome);
204
+ }
205
+ }
206
+ return template.replace(/\{(v|deviceModel|language)\}/g, (_, token) => {
207
+ if (token === 'v')
208
+ return version;
209
+ if (token === 'deviceModel')
210
+ return deviceModel;
211
+ return options.language ?? profile.policies?.defaultLanguage ?? 'zh-Hans';
212
+ });
191
213
  }
192
214
  return os === 'android'
193
215
  ? `Mozilla/5.0 (Linux; Android 17; ${deviceModel}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/152.0.0.0 Mobile Safari/537.36`
@@ -245,14 +267,21 @@ export function resolveAppProfileDefinition(definition, options = {}) {
245
267
  preset: devicePreset,
246
268
  orientation: options.orientation,
247
269
  });
248
- const deviceModel = options.deviceModel ?? DEVICE_PRESETS[devicePreset].appProfileModel;
249
- const globals = profile.pageRuntime || profile.bridges.length > 0 || Object.keys(profile.globals).length > 0 ? {
250
- ...Object.fromEntries(Object.entries(profile.globals).map(([key, value]) => [key, value.replaceAll('{deviceModel}', deviceModel).replaceAll('{v}', version)])),
251
- __APP_NAME__: profile.appName,
252
- __APP_VERSION__: version,
253
- __DEVICE_MODEL__: deviceModel,
254
- } : {};
255
- const ua = buildAppProfileUa(profile, { ...options, os, deviceModel });
270
+ const preset = DEVICE_PRESETS[devicePreset];
271
+ const deviceModel = options.deviceModel ?? preset.appProfileModel;
272
+ const matchingDevice = profile.uaFamily === 'device-webview' && preset.appProfileOs === os ? preset : undefined;
273
+ const globals = profile.pageRuntime || profile.bridges.length > 0 || Object.keys(profile.globals).length > 0
274
+ ? {
275
+ ...Object.fromEntries(Object.entries(profile.globals).map(([key, value]) => [
276
+ key,
277
+ value.replaceAll('{deviceModel}', deviceModel).replaceAll('{v}', version),
278
+ ])),
279
+ __APP_NAME__: profile.appName,
280
+ __APP_VERSION__: version,
281
+ __DEVICE_MODEL__: deviceModel,
282
+ }
283
+ : {};
284
+ const ua = buildAppProfileUa(profile, { ...options, os, devicePreset, deviceModel });
256
285
  return {
257
286
  profile: profile.name,
258
287
  label: profile.label,
@@ -286,10 +315,18 @@ export function resolveAppProfileDefinition(definition, options = {}) {
286
315
  language: options.language ?? profile.policies?.defaultLanguage ?? 'zh-Hans',
287
316
  // UA 随注入配置一起下发,供 DNR、页内运行时和动态 WebView 导航前刷新使用
288
317
  userAgent: ua,
289
- navigatorPlatform: os === 'android' ? 'Linux armv8l' : 'iPhone',
318
+ navigatorPlatform: os === 'android'
319
+ ? 'Linux armv8l'
320
+ : (matchingDevice?.appProfileIosIdentity?.navigatorPlatform ?? 'iPhone'),
290
321
  // systemInfo 使用产品系统版本;Safari UA 中的系统 token 可能是兼容性固定值。
291
322
  platform: os === 'android' ? 'Android' : 'iOS',
292
- systemVersion: os === 'android' ? '17' : '26.0',
323
+ systemVersion: os === 'android'
324
+ ? matchingDevice?.platform === 'Android'
325
+ ? matchingDevice.platformVersion
326
+ : '17'
327
+ : (matchingDevice?.appProfileIosIdentity?.systemVersion ??
328
+ matchingDevice?.platformVersion ??
329
+ '26.0'),
293
330
  clientType: os === 'android' ? 'android' : 'iphone',
294
331
  actions: applyAppBridgeConfig(profile.actions, options.bridgeConfig),
295
332
  schemes: profile.schemes,
@@ -301,7 +338,9 @@ export function resolveAppProfileDefinition(definition, options = {}) {
301
338
  ...(profile.nativeBack && { nativeBack: profile.nativeBack }),
302
339
  ...(profile.layerUrlProxy && { layerUrlProxy: profile.layerUrlProxy }),
303
340
  ...(profile.urlSyncHostSuffixes && { urlSyncHostSuffixes: profile.urlSyncHostSuffixes }),
304
- ...(profile.runtimeOptions && { runtimeOptions: JSON.parse(JSON.stringify(profile.runtimeOptions)) }),
341
+ ...(profile.runtimeOptions && {
342
+ runtimeOptions: JSON.parse(JSON.stringify(profile.runtimeOptions)),
343
+ }),
305
344
  simulateSystemBars: false,
306
345
  externalDeviceChrome: false,
307
346
  rootContainer: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mearl/app-profiles",
3
- "version": "3.1.3",
3
+ "version": "3.1.4",
4
4
  "description": "Declarative App profile compilation for installed capabilities",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -25,7 +25,7 @@
25
25
  ],
26
26
  "license": "Apache-2.0",
27
27
  "dependencies": {
28
- "@mearl/browser-core": "3.1.3"
28
+ "@mearl/browser-core": "3.1.4"
29
29
  },
30
30
  "devDependencies": {
31
31
  "typescript": "^5.8.3"