Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

380
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda