capture-electron icon indicating copy to clipboard operation
capture-electron copied to clipboard

s.replace is not a function

Open u12206050 opened this issue 6 years ago • 10 comments

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)

u12206050 avatar Oct 13 '19 08:10 u12206050

Can you please share the error you're getting?

juliangruber avatar Oct 13 '19 18:10 juliangruber

@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.

KeJunMao avatar Apr 17 '20 17:04 KeJunMao

Awesome Library!!! I'm use typescrpit, can you add d.ts ? THX Looking forward to your Hui

KeJunMao avatar Apr 17 '20 17:04 KeJunMao

That error seems to appear when either of url, width, 'height', wait or format is not a string or number. Can you verify that?

juliangruber avatar Apr 20 '20 08:04 juliangruber

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:

image

TypeError: s.replace is not a function

PS: My Electron version: 6.0.0

KeJunMao avatar Apr 20 '20 10:04 KeJunMao

Thanks! Can you try this?

node -pe 'require("electron")'

It seems like the electron module isn't exposing its path on your machine

juliangruber avatar Apr 20 '20 12:04 juliangruber

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

KeJunMao avatar Apr 21 '20 01:04 KeJunMao

can you please try version 3.0.2?

juliangruber avatar Apr 23 '20 17:04 juliangruber

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 ?

niemes avatar Aug 16 '20 13:08 niemes

I have the same problem on Electron 11.5 using "capture-electron"

zghbyslzf avatar Sep 16 '22 10:09 zghbyslzf