Skip to content

WebFrame#executeJavascriptInIsolatedWorld is not rejecting on error #22490

Closed

Description

@bughit

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project adheres to.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

Issue Details

  • Electron Version:
    • v9.0.0-beta.5 x86
  • Operating System:
    • win7 x64 sp1

Expected Behavior

The returned promise should reject if js eval fails.

Actual Behavior

The promise resolves with undefined.

To Reproduce

  1. run this app
    'use strict';
    
    const {app, BrowserWindow} = require('electron');
    
    let win;
    
    app.on('ready', async () => {
    
      win = new BrowserWindow({
        width: 1440,
        height: 900,
        useContentSize: true,
        webPreferences: {
          nodeIntegration: true,
        },
      });
    
      win.webContents.openDevTools({mode: 'right'});
      win.loadURL('about:blank');
    
    });
  2. eval the following in the js console
    try {const r = await require('electron').webFrame.executeJavaScriptInIsolatedWorld(999, [{code: 'thisShouldProduceAnError()'}]); console.log(`executeJavaScriptInIsolatedWorld resolved with ${r}, instead of rejecting`);} catch {}

Activity

  1. added
    blocked/upstream ❌
    and removed on May 19, 2020
  2. zcbenz commented on May 19, 2020

    @zcbenz
    Contributor

    This is unfortunately by design in Chromium, see:
    https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/renderer/core/frame/pausable_script_executor.cc;l=62-72

        // Note: An error event in an isolated world will never be dispatched to
        // a foreign world.
    

    Fix this requires patching Chromium, and we need to be very careful to not break other things. So I prefer documenting this behavior instead of fixing it.

  3. bughit commented on May 19, 2020

    @bughit
    ContributorAuthor

    @zcbenz please take a look at @MarshallOfSound's commit 0fc172f

    ScriptExecutionCallback was enhanced to detect execution failure and reject, not with the original error but nevertheless an error, which is better than a resolve. This code is common to executeJavascript and executeJavascriptInIsolatedWorld. It works for executeJavascript but not for executeJavascriptInIsolatedWorld.

    The purpose of this bug is not to get the original error but to achieve the clearly intended parity, if possible, with executeJavascript.

  4. zcbenz commented on May 19, 2020

    @zcbenz
    Contributor

    There is nothing wrong on our code, it is Chromium that intentionally hides the error from us. Chromium checks if the script is executed in isolated world, and if it is then Chromium would return undefined as result even when the execution fails, so there is no way on our side to know if the execution failed. (For main world an empty handle would be returned for failed executions.)

    The only way to fix this is to patch Chromium, but this is security related code and patch would be relatively large, I think it would be too risky.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    blocked/upstream ❌bug 🪲

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions