Skip to content

Commit

Permalink
PKG -- [fcl] Throw error on popup blocked, show error if sendMsgToFCL…
Browse files Browse the repository at this point in the history
… parent reference doesn't exist (#1274)
  • Loading branch information
jribbink authored Jun 30, 2022
1 parent 8d2f8a6 commit 865e412
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/lovely-candles-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@onflow/fcl": patch
---

Throw error if FCL popup is blocked. Show "session expired" if sendMsgToFCL cannot access parent window for postMessage.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ let previousUrl = null
function popupWindow(url, windowName, win, w, h) {
const y = win.top.outerHeight / 2 + win.top.screenY - h / 2
const x = win.top.outerWidth / 2 + win.top.screenX - w / 2
return win.open(
const popup = win.open(
url,
windowName,
`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=${w}, height=${h}, top=${y}, left=${x}`
)
if (!popup)
throw new Error("Popup failed to open (was it blocked by a popup blocker?)")
return popup
}

export function renderPop(src) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ let previousUrl = null
export function renderTab(src) {
if (tab == null || tab?.closed) {
tab = window.open(src, "_blank")
if (!tab)
throw new Error("Tab failed to open (was it blocked by the browser?)")
} else if (previousUrl !== src) {
tab.location.replace(src)
tab.focus()
Expand Down
4 changes: 3 additions & 1 deletion packages/fcl/src/wallet-utils/send-msg-to-fcl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import {onMessageFromFCL} from "./on-message-from-fcl"
export const sendMsgToFCL = (type, msg = {}) => {
if (window.location !== window.parent.location) {
window.parent.postMessage({...msg, type}, "*")
} else {
} else if (window.opener) {
window.opener.postMessage({...msg, type}, "*")
} else {
throw new Error("Unable to communicate with parent FCL instance")
}
}

Expand Down

0 comments on commit 865e412

Please sign in to comment.