From 65194501008fa448058214cf0a6f9016ad88272e Mon Sep 17 00:00:00 2001 From: Bruno Barbieri Date: Wed, 13 Nov 2019 20:44:53 -0500 Subject: [PATCH 1/4] check main frame, then try iframes --- app/util/browserScripts.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/app/util/browserScripts.js b/app/util/browserScripts.js index b9848038233..dcc87df2926 100644 --- a/app/util/browserScripts.js +++ b/app/util/browserScripts.js @@ -97,19 +97,27 @@ export const JS_DESELECT_TEXT = `if (window.getSelection) {window.getSelection() else if (document.selection) {document.selection.empty();}`; export const JS_POST_MESSAGE_TO_PROVIDER = (message, origin) => `(function () { + let found = false; try { - window.postMessage(${JSON.stringify(message)}, '${origin}'); + const msg = ${message}; + const __mmID = msg && msg.payload.__mmID; + if(window.ethereum._pending[__mmID]){ + window.postMessage(${JSON.stringify(message)}, '${origin}'); + found = true; + } } catch (e) { //Nothing to do } - const iframes = document.getElementsByTagName('iframe'); - let sent = false; - for (let frame of iframes){ - if(frame.src === '${origin}'){ - try { - frame.contentWindow.postMessage(${JSON.stringify(message)}, '${origin}'); - } catch (e) { - //Nothing to do + if(!found){ + const iframes = document.getElementsByTagName('iframe'); + let sent = false; + for (let frame of iframes){ + if(frame.src === '${origin}'){ + try { + frame.contentWindow.postMessage(${JSON.stringify(message)}, '${origin}'); + } catch (e) { + //Nothing to do + } } } } From 11b5b10d07e357ae5a0e0ca6fa23e87d5da1a630 Mon Sep 17 00:00:00 2001 From: Bruno Barbieri Date: Wed, 13 Nov 2019 22:51:00 -0500 Subject: [PATCH 2/4] fix ios device names --- package.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 00f6d2ea4eb..61a7270b10b 100644 --- a/package.json +++ b/package.json @@ -221,13 +221,17 @@ "binaryPath": "ios/build/MetaMask/Build/Products/Debug-iphonesimulator/MetaMask.app", "build": "yarn start:ios", "type": "ios.simulator", - "name": "iPhone 11 Pro" + "device": { + "type": "iPhone 11 Pro" + } }, "ios.sim.release": { "binaryPath": "ios/build/MetaMask/Build/Products/Release-iphonesimulator/MetaMask.app", "build": "yarn build:ios:release", "type": "ios.simulator", - "name": "iPhone 11 Pro" + "device": { + "type": "iPhone 11 Pro" + } }, "android.emu.debug": { "binaryPath": "android/app/build/outputs/apk/debug/app-debug.apk", From 02014c4cd17b5161fb82bc628467d4823dc8983c Mon Sep 17 00:00:00 2001 From: Bruno Barbieri Date: Wed, 13 Nov 2019 23:07:31 -0500 Subject: [PATCH 3/4] fix --- app/util/browserScripts.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/util/browserScripts.js b/app/util/browserScripts.js index dcc87df2926..484bd5704a3 100644 --- a/app/util/browserScripts.js +++ b/app/util/browserScripts.js @@ -99,21 +99,25 @@ else if (document.selection) {document.selection.empty();}`; export const JS_POST_MESSAGE_TO_PROVIDER = (message, origin) => `(function () { let found = false; try { + window.postMessage(${JSON.stringify(message)}, '${origin}'); const msg = ${message}; + console.log('SENDING MSG TO PROVIDER', msg); const __mmID = msg && msg.payload.__mmID; if(window.ethereum._pending[__mmID]){ - window.postMessage(${JSON.stringify(message)}, '${origin}'); found = true; } } catch (e) { //Nothing to do } if(!found){ + console.log('Checking on iframes'); const iframes = document.getElementsByTagName('iframe'); let sent = false; for (let frame of iframes){ if(frame.src === '${origin}'){ + console.log('FOUND IN IFRAME WITH ORIGIN', frame.src); try { + console.log('SENDING TO IFRAME'); frame.contentWindow.postMessage(${JSON.stringify(message)}, '${origin}'); } catch (e) { //Nothing to do From da8db112046d99f43c296512a09cd322bf56f5f3 Mon Sep 17 00:00:00 2001 From: Bruno Barbieri Date: Wed, 13 Nov 2019 23:32:04 -0500 Subject: [PATCH 4/4] remove console logs --- app/util/browserScripts.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/util/browserScripts.js b/app/util/browserScripts.js index 484bd5704a3..71ff8116a86 100644 --- a/app/util/browserScripts.js +++ b/app/util/browserScripts.js @@ -101,7 +101,6 @@ export const JS_POST_MESSAGE_TO_PROVIDER = (message, origin) => `(function () { try { window.postMessage(${JSON.stringify(message)}, '${origin}'); const msg = ${message}; - console.log('SENDING MSG TO PROVIDER', msg); const __mmID = msg && msg.payload.__mmID; if(window.ethereum._pending[__mmID]){ found = true; @@ -110,14 +109,11 @@ export const JS_POST_MESSAGE_TO_PROVIDER = (message, origin) => `(function () { //Nothing to do } if(!found){ - console.log('Checking on iframes'); const iframes = document.getElementsByTagName('iframe'); let sent = false; for (let frame of iframes){ if(frame.src === '${origin}'){ - console.log('FOUND IN IFRAME WITH ORIGIN', frame.src); try { - console.log('SENDING TO IFRAME'); frame.contentWindow.postMessage(${JSON.stringify(message)}, '${origin}'); } catch (e) { //Nothing to do