Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

379
Views
Electron.js registerFileProtocol for relative paths without resolution

We need to generate from user's HTML templates PDF to a temp dir and then copy the result to the proper target location. The template files may contain relative paths to images or CSS. So, our code does:

  1. protocol.registerSchemesAsPrivileged([{ scheme: "pdffile", privileges: { standard: true } }])
  2. protocol.registerFileProtocol("pdffile", (request, callback) => /* handler */ )
  3. win.loadURL("pdffile://root/pdf.html"})

The problem is with parent dirs .. pointers. E.g.

  • src="img.png" resolves to request.url = pdffile://root/img.png" in the handler. That's OK.
  • src="../img.png" resolves to the same request.url = pdffile://root/img.png" in the handler. And that's the problem, because we cannot load the user's image from the proper location.

Is there any way how to force Electron NOT to do relative path resolution and send the raw string "../img.png" to the handler?

Note: ugly workaround is to make base URL like win.loadURL("pdffile://root/1/2/3/4/5/6/7/8/9/0/pdf.html"}) and guess the relative part from request.url then.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!