s.replace is not a function
It seems it is trying to run "shellescape" function on an object.
This is the array that is sent to shellescape:
0: { // THIS OBJECT BREAKS IT
// It seems to be an electron instance.
}
1:"/Users/…/…/…/node_modules/capture-electron/script/render.js"
2:"http://localhost:40404/"
3:1024
4:768
5:0
6: "png"
It is called here
exec(
escape([
electron,
`${__dirname}/script/render.js`,
url,
width,
height,
wait,
format.toLowerCase()
]),
{ maxBuffer: Infinity, encoding: 'buffer' }
).then(({ stdout }) => stdout)
Can you please share the error you're getting?
@juliangruber I have the same error
(node:1387) UnhandledPromiseRejectionWarning: TypeError: s.replace is not a function
at eval (webpack:///./node_modules/shell-escape/shell-escape.js?:9:17)
at Array.forEach (<anonymous>)
at shellescape (webpack:///./node_modules/shell-escape/shell-escape.js?:7:5)
at module.exports (webpack:///./node_modules/capture-electron/index.js?:15:5)
at EventEmitter.eval (webpack:///./src/ipc/main/getPagger.ts?:9:72)
at EventEmitter.emit (events.js:200:13)
at WebContents.<anonymous> (/Users/kejun/WorkSpace/storyline-push/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/browser/api/web-contents.js:335:21)
at WebContents.emit (events.js:200:13)
(node:1387) UnhandledPromiseRejectionWarning: TypeError: s.replace is not a function
at eval (webpack:///./node_modules/shell-escape/shell-escape.js?:9:17)
at Array.forEach (<anonymous>)
at shellescape (webpack:///./node_modules/shell-escape/shell-escape.js?:7:5)
at module.exports (webpack:///./node_modules/capture-electron/index.js?:15:5)
at EventEmitter.eval (webpack:///./src/ipc/main/getPagger.ts?:9:72)
at EventEmitter.emit (events.js:200:13)
at WebContents.<anonymous> (/Users/kejun/WorkSpace/storyline-push/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/browser/api/web-contents.js:335:21)
at WebContents.emit (events.js:200:13)
(node:1387) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:1387) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:1387) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:1387) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Awesome Library!!!
I'm use typescrpit, can you add d.ts ? THX
Looking forward to your Hui
That error seems to appear when either of url, width, 'height', wait or format is not a string or number. Can you verify that?
Thank you for your reply! I just use it simply:
capture({ url: "https://github.com/" }).then((s) => console.log(s));
After debugging, I found that:
escape([
electron, // electron.replace is not a function
`${__dirname}/script/render.js`,
url,
width,
height,
wait,
format.toLowerCase(),
]);
shell-escape.js:

TypeError: s.replace is not a function
PS: My Electron version: 6.0.0
Thanks! Can you try this?
node -pe 'require("electron")'
It seems like the electron module isn't exposing its path on your machine
Thank you for your reply!
$node -pe 'require("electron")'
/Path/To/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron
Then, I'm try call render.js , got new Error:
$/Path/To/Electron /Path/To/capture-electron/script/render.js https://github.com 300 400 5 jpg
Uncaught Exception:
TypeError: Insufficient number of arguments.
at /Path/To/node_modules/capture-electron/script/render.js:22:19
at /Path/To/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/common/api/deprecate.js:122:55
at processTicksAndRejections (internal/process/task_queues.js:82:9)
script/render.js:19 call win.capturePage
capturePage doc, Returns Promise<NativeImage>
Is this module out of date?
My English is poor...Forgive
can you please try version 3.0.2?
I have the same problem on Electron 9.2.0 using "capture-electron": "^3.0.2"
Uncaught TypeError: s.replace is not a function
Any quickFix ?
I have the same problem on Electron 11.5 using "capture-electron"