I've got an array of instagram media data prepared for embedding. In the end of each html there's a script <script async defer src="//platform.instagram.com/en_US/embeds.js"></script>
.
By default electron refers this link to the file://
protocol. Adding http://
in src return js file correctly.
So link <script async defer src="http://platform.instagram.com/en_US/embeds.js"></script>
works fine.
How can I solve this problem except parsing data and rewriting link?
The problem you are facing is that //
is a protocol relative URL that will use whatever protocol the file requesting it is. You can read more about that here.
your best bet to override this default behaviour would be to either parse the data and rewrite the links with something like a regex query.
or you can attempt to intercept the file protocol, verify that the url is one you want to intercept, then reformat the url, you can learn about how to do this here. with an example that does not include the verification of the paths you wish to intercept below.
const {app, protocol} = require('electron')
const path = require('path')
app.on('ready', () => {
protocol.registerFileProtocol('file', (request, callback) => {
const url = request.url.substr(7)
callback({path: path.normalize(`http://${__dirname}/${url}`)})
}, (error) => {
if (error) console.error('Failed to register protocol')
})
})