diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 0d52112b08..a8f864c775 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1327,9 +1327,17 @@ void WebContents::StartDrag(const mate::Dictionary& item, // Error checking. if (icon.IsEmpty()) { + args->ThrowError("Must specify 'icon' option"); + return; + } + +#if defined(OS_MACOSX) + // NSWindow.dragImage requires a non-empty NSImage + if (icon->image().IsEmpty()) { args->ThrowError("Must specify non-empty 'icon' option"); return; } +#endif // Start dragging. if (!files.empty()) { diff --git a/spec/api-web-contents-spec.js b/spec/api-web-contents-spec.js index 417b8d5046..98aa1169e6 100644 --- a/spec/api-web-contents-spec.js +++ b/spec/api-web-contents-spec.js @@ -292,13 +292,15 @@ describe('webContents module', function () { w.webContents.startDrag({icon: path.join(__dirname, 'fixtures', 'assets', 'logo.png')}) }, /Must specify either 'file' or 'files' option/) - assert.throws(() => { - w.webContents.startDrag({file: __filename, icon: __filename}) - }, /Must specify non-empty 'icon' option/) - assert.throws(() => { w.webContents.startDrag({file: __filename}) - }, /Must specify non-empty 'icon' option/) + }, /Must specify 'icon' option/) + + if (process.platform === 'darwin') { + assert.throws(() => { + w.webContents.startDrag({file: __filename, icon: __filename}) + }, /Must specify non-empty 'icon' option/) + } }) }) })