Merge pull request #5118 from electron/webview-no-script
Fix webview and preload script not working when there is no script tag in page
This commit is contained in:
commit
c9a3fc4317
4 changed files with 38 additions and 1 deletions
|
@ -27,6 +27,7 @@
|
|||
#include "third_party/WebKit/public/web/WebFrame.h"
|
||||
#include "third_party/WebKit/public/web/WebLocalFrame.h"
|
||||
#include "third_party/WebKit/public/web/WebKit.h"
|
||||
#include "third_party/WebKit/public/web/WebScriptSource.h"
|
||||
#include "third_party/WebKit/public/web/WebView.h"
|
||||
#include "ui/base/resource/resource_bundle.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
|
@ -88,6 +89,9 @@ void AtomRenderViewObserver::DidCreateDocumentElement(
|
|||
blink::WebLocalFrame* frame) {
|
||||
document_created_ = true;
|
||||
|
||||
// Make sure every page will get a script context created.
|
||||
frame->executeScript(blink::WebScriptSource("void 0"));
|
||||
|
||||
// Read --zoom-factor from command line.
|
||||
std::string zoom_factor_str = base::CommandLine::ForCurrentProcess()->
|
||||
GetSwitchValueASCII(switches::kZoomFactor);
|
||||
|
|
7
spec/fixtures/pages/ping.html
vendored
Normal file
7
spec/fixtures/pages/ping.html
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
<html>
|
||||
<body>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
require('electron').ipcRenderer.send('pong')
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
5
spec/fixtures/pages/webview-no-script.html
vendored
Normal file
5
spec/fixtures/pages/webview-no-script.html
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
<html>
|
||||
<body>
|
||||
<webview nodeintegration src="ping.html"/>
|
||||
</body>
|
||||
</html>
|
|
@ -2,7 +2,7 @@ const assert = require('assert')
|
|||
const path = require('path')
|
||||
const http = require('http')
|
||||
const url = require('url')
|
||||
const {app, session} = require('electron').remote
|
||||
const {app, session, ipcMain, BrowserWindow} = require('electron').remote
|
||||
|
||||
describe('<webview> tag', function () {
|
||||
this.timeout(10000)
|
||||
|
@ -20,6 +20,15 @@ describe('<webview> tag', function () {
|
|||
}
|
||||
})
|
||||
|
||||
it('works without script tag in page', function (done) {
|
||||
let w = new BrowserWindow({show: false})
|
||||
ipcMain.once('pong', function () {
|
||||
w.destroy()
|
||||
done()
|
||||
})
|
||||
w.loadURL('file://' + fixtures + '/pages/webview-no-script.html')
|
||||
})
|
||||
|
||||
describe('src attribute', function () {
|
||||
it('specifies the page to load', function (done) {
|
||||
webview.addEventListener('console-message', function (e) {
|
||||
|
@ -155,6 +164,18 @@ describe('<webview> tag', function () {
|
|||
webview.src = 'file://' + fixtures + '/pages/e.html'
|
||||
document.body.appendChild(webview)
|
||||
})
|
||||
|
||||
it('works without script tag in page', function (done) {
|
||||
var listener = function (e) {
|
||||
assert.equal(e.message, 'function object object')
|
||||
webview.removeEventListener('console-message', listener)
|
||||
done()
|
||||
}
|
||||
webview.addEventListener('console-message', listener)
|
||||
webview.setAttribute('preload', fixtures + '/module/preload.js')
|
||||
webview.src = 'file://' + fixtures + '/pages/base-page.html'
|
||||
document.body.appendChild(webview)
|
||||
})
|
||||
})
|
||||
|
||||
describe('httpreferrer attribute', function () {
|
||||
|
|
Loading…
Reference in a new issue