Skip to content
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

Optimize injection on Iframes #1199

Merged
merged 4 commits into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions app/util/browserScripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]){
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
}
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down