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:
protocol.registerSchemesAsPrivileged([{ scheme: "pdffile", privileges: { standard: true } }])protocol.registerFileProtocol("pdffile", (request, callback) => /* handler */ )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.