Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

381
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda