Skip to content

Commit

Permalink
fix: 修复钉钉环境post message
Browse files Browse the repository at this point in the history
  • Loading branch information
zx209439 committed Dec 5, 2022
1 parent a028651 commit 726ad06
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/tb-apps-sdk/src/sdk/AppSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class AppSDK {
this.targetId = resp.data.targetId
this.targetOrigin = resp.data.origin
this.initialize = true
this.source = resp.source as Window
this.source = this.getSource(resp.source as Window)
this.sameOrigin = resp.data.origin === document.location.origin
this.connector.resolve()
}
Expand Down Expand Up @@ -169,4 +169,12 @@ export class AppSDK {
)
}

private getSource(source) {
// 钉钉环境会改变 window,导致 source.postMessage 无法发送成功,此时使用 window.parent
// 钉钉环境改变 window, 无法使用 source.navigator.userAgent 验证
if (window && window.navigator && /DingTalk/.test(window.navigator.userAgent)) {
return window.parent
}
return source
}
}

0 comments on commit 726ad06

Please sign in to comment.