Skip to content

支持原生鸿蒙UA,否则纯血鸿蒙手机下_isMobile 返回非预期的 false #5569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: next
Choose a base branch
from

Conversation

mayunhai
Copy link

举例说明:
Mozilla/5.0 (Phone; OpenHarmony 5.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 ArkWeb/4.1.6.1 Mobile

// iphone return true
/android|phone/i.test('mozilla/5.0 (iphone; cpu iphone os 16_6 like mac os x) applewebkit/605.1.15 (khtml, like gecko) version/16.6 mobile/15e148 safari/604.1')
// openharmony  return true
/android|phone/i.test('mozilla/5.0 (phone; openharmony 5.0) applewebkit/537.36 (khtml, like gecko) chrome/114.0.0.0 safari/537.36  arkweb/4.1.6.1 mobile')

举例说明:
Mozilla/5.0 (Phone; OpenHarmony 5.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36  ArkWeb/4.1.6.1 Mobile
```javascript
// iphone return true
/android|phone/i.test('mozilla/5.0 (iphone; cpu iphone os 16_6 like mac os x) applewebkit/605.1.15 (khtml, like gecko) version/16.6 mobile/15e148 safari/604.1')
// openharmony  return true
/android|phone/i.test('mozilla/5.0 (phone; openharmony 5.0) applewebkit/537.36 (khtml, like gecko) chrome/114.0.0.0 safari/537.36  arkweb/4.1.6.1 mobile')
```
@mayunhai mayunhai changed the title 支持原生鸿蒙UA,否则纯血鸿蒙手机下_isMobile 返回非预期的 true 支持原生鸿蒙UA,否则纯血鸿蒙手机下_isMobile 返回非预期的 false Jun 19, 2025
@Otto-J
Copy link
Member

Otto-J commented Jul 1, 2025

这个是广告服务内的逻辑,鸿蒙侧你们在使用了吗?

@Otto-J Otto-J requested a review from Copilot July 1, 2025 09:53
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the user agent detection logic for mobile devices to correctly recognize OpenHarmony devices.

  • Updated the regular expression in the _isMobile method from matching "iphone" to "phone".

@@ -146,7 +146,7 @@ export default {
},

_isMobile () {
return /android|iphone/i.test(navigator.userAgent.toLowerCase())
return /android|phone/i.test(navigator.userAgent.toLowerCase())
Copy link
Preview

Copilot AI Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The call to toLowerCase() is redundant because the regex already uses the case-insensitive flag 'i'. Consider removing .toLowerCase() to simplify the code.

Suggested change
return /android|phone/i.test(navigator.userAgent.toLowerCase())
return /android|phone/i.test(navigator.userAgent)

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants