Skip to content

vm.runInNewContext() & console.log causes devtools to disconnect #7814

Closed

Description

@michaelbromley
  • Electron version: 1.4.3
  • Operating system: Windows 10 x64

I am building an app which runs user scripts in a sandboxed environment, so I want to use the Node vm module. Here is the code I use to load the user scripts:

function runInSandbox(visPath: string): IVisualization {
    let context = {
        require: (moduleName) => {
            // I implement a custom "safe" require method here
        },
        console: console,
        module: {}
    };
    let data = fs.readFileSync(path.join(visPath, 'index.js'));
    let result = vm.runInNewContext(data, context, { visPath });
    return result;
}
// userscript/index.js
console.log('test');

Now, when I run the app without devtools open, the user scripts execute as expected. However, when I am running with the devtools open, as soon as one of the user scripts does a console.log, the devtools crashes with:

DevTools was disconnected from the page.
Once the page is reloaded, DevTools will automatically reconnect.

electron-crash

However, if I define the console object in the context thus:

console: {
  log: (...args) => console.log(...args),
 },

then the script works fine and DevTools does not disconnect, which seems strange, since I have seen many examples online where the console object is defined as in the first example.

Activity

  1. kevinsawicki commented on Jan 6, 2017

    @kevinsawicki
    Contributor

    The stack trace for this one is:

    0   libwebcore_shared.dylib       	0x000000010c4cdf68 blink::BindingSecurity::shouldAllowAccessTo(v8::Isolate*, v8::Local<v8::Context>, v8::Local<v8::Context>, blink::SecurityReportingOption) + 200
    1   libblink_platform.dylib       	0x000000010790b949 0x1077ba000 + 1382729
    2   libblink_platform.dylib       	0x000000010790b75f 0x1077ba000 + 1382239
    3   libblink_platform.dylib       	0x0000000107932332 0x1077ba000 + 1540914
    4   libblink_platform.dylib       	0x0000000107911b7a 0x1077ba000 + 1407866
    5   libblink_platform.dylib       	0x0000000107911790 0x1077ba000 + 1406864
    6   libblink_platform.dylib       	0x0000000107910eb7 0x1077ba000 + 1404599
    7   libblink_platform.dylib       	0x0000000107912948 0x1077ba000 + 1411400
    8   libblink_platform.dylib       	0x00000001079302ba 0x1077ba000 + 1532602
    9   libblink_platform.dylib       	0x000000010792cd30 0x1077ba000 + 1518896
    10  libblink_platform.dylib       	0x000000010792ceba 0x1077ba000 + 1519290
    11  libv8.dylib                   	0x000000010698fd9a v8::internal::FunctionCallbackArguments::Call(void (*)(v8::FunctionCallbackInfo<v8::Value> const&)) + 298
    12  libv8.dylib                   	0x00000001069ca01e 0x10695d000 + 446494
    13  libv8.dylib                   	0x00000001069f48af 0x10695d000 + 620719
    14  ???                           	0x00003a50a2a06147 0 + 64118000214343
    15  ???                           	0x00003a50a2b91ded 0 + 64118001835501
    16  ???                           	0x00003a50a2a42263 0 + 64118000460387
    17  ???                           	0x00003a50a2a25d6f 0 + 64118000344431
    18  libv8.dylib                   	0x0000000106cb0570 0x10695d000 + 3487088
    19  libv8.dylib                   	0x0000000106cb0379 v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, int, v8::internal::Handle<v8::internal::Object>*) + 313
    20  libv8.dylib                   	0x000000010696a639 v8::Script::Run(v8::Local<v8::Context>) + 601
    21  libnode.dylib                 	0x00000001060b9710 node::ContextifyScript::EvalMachine(node::Environment*, long long, bool, bool, v8::FunctionCallbackInfo<v8::Value> const&, v8::TryCatch*) + 672 (node_contextify.cc:866)
    22  libnode.dylib                 	0x00000001060b79cd node::ContextifyScript::RunInContext(v8::FunctionCallbackInfo<v8::Value> const&) + 525 (node_contextify.cc:619)
    
  2. kevinsawicki commented on Jan 6, 2017

    @kevinsawicki
    Contributor

    This looks to be fixed in Chrome 54, I can't reproduce this on the #7909 branch.

    screen shot 2017-01-05 at 4 09 44 pm

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions