Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Fix opener access errors #133

Merged
merged 4 commits into from
Jul 10, 2018
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
22 changes: 22 additions & 0 deletions src/__tests__/index.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,25 @@ test('Get exception stack frames', t => {

t.end();
});

test("Don't break on cross-origin exceptions", t => {
t.plan(1);

const app = new App('test', el => el);

window.opener = new Proxy(
{},
{
get: () => {
// Simulate an Exception on all access to `window.opener`
throw new Error('Simulated `DOMException`');
},
}
);

app.register(ErrorHandlingPlugin);

t.doesNotThrow(() => getSimulator(app));

t.end();
});
9 changes: 8 additions & 1 deletion src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const plugin =
throw e;
};
}
for (const key in window) {
const addListener = key => {
if (
key.match(/webkit/) == null && // stop deprecation warnings
window[key] &&
Expand All @@ -55,6 +55,13 @@ const plugin =
return old.call(this, type, cb, ...rest);
};
}
};
for (const key in window) {
try {
addListener(key);
} catch (e) {
// Ignore. Don't have access to the prop, possibly cross-origin restriction.
}
}
window.addEventListener('unhandledrejection', e => {
e.preventDefault();
Expand Down