Petr Felzmann
Petr Felzmann

Reputation: 1313

iframe with local resource in Electron

I need to render iframe in my Electron application:

<!DOCTYPE html>
<html>
  <head>
    <title></title>
  </head>
  <body>
    <iframe sandbox='allow-scripts' src='frm.html'></iframe>
  </body>
</html>

where the frm.html links the local file script foo.js which is part of my Electron application

<!DOCTYPE HTML>
<html>
<head>
    <title></title>
    <script src="foo.js"></script>
</head>
<body>
    <p>Inside iframe</p>
</body>
</html>

When I run the application in Electron I can see this error in devtools console

Not allowed to load local resource: file:///C:/electron/app1/foo.js

Is it possible such scenario in Electron?

Upvotes: 5

Views: 12439

Answers (1)

Shawn Rakowski
Shawn Rakowski

Reputation: 5714

This is a security feature of the iframe. Here is a similar question that talks about loading linked files into an iframe: Displaying local htm file in iframe?.

That being said, have you considered using the webview tag instead? http://electron.atom.io/docs/v0.30.0/api/web-view-tag/. The webview tag is very similar to an iframe, but gives you more ability to control the security around it. I tested loading a local file into a webview in the same way you attempt to load frm.html into the iframe and it works flawlessly.

Upvotes: 6

Related Questions