diff --git a/packages/app-js/src/index.tsx b/packages/app-js/src/index.tsx index d827e85246..f425bff289 100644 --- a/packages/app-js/src/index.tsx +++ b/packages/app-js/src/index.tsx @@ -108,7 +108,7 @@ class App extends React.PureComponent { ); } - private runJs = (): void => { + private runJs = async (): Promise => { const { api } = this.props; const { code } = this.state; const { keyring } = uiKeyring; @@ -129,6 +129,8 @@ class App extends React.PureComponent { window: null }; + await this.injected.api.isReady; + // squash into a single line so exceptions (with linenumbers) maps to the same line/origin // as we have in the editor view (TODO: Make the console.error here actually return the full stack) const exec = `(async ({${Object.keys(this.injected).join(',')}}) => { try { ${code} } catch (error) { console.error(error); } })(injected);`;