-
-
Save likr/1e452c10395d7ad2bc993e10cfdeb613 to your computer and use it in GitHub Desktop.
プリレンダリングのテスト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* global phantom */ | |
| var url = 'http://localhost:8080/posts' | |
| function ready () { | |
| console.log(window.fetch) | |
| return window.prerenderReady | |
| } | |
| var page = require('webpage').create() | |
| page.onResourceRequested = function (request) { | |
| console.log('Request ' + JSON.stringify(request, undefined, 4)) | |
| } | |
| page.onResourceReceived = function (response) { | |
| console.log('Receive ' + JSON.stringify(response, undefined, 4)) | |
| } | |
| page.open(url, function (status) { | |
| console.log('hoge', status) | |
| if (status === 'success') { | |
| page.render('example.png') | |
| } | |
| setInterval(function () { | |
| var finished = page.evaluate(ready) | |
| console.log(finished) | |
| if (finished) { | |
| phantom.exit() | |
| } | |
| page.render('hoge.png') | |
| }, 1000) | |
| }) | |
| page.onError = function (msg, trace) { | |
| var msgStack = ['ERROR: ' + msg] | |
| if (trace && trace.length) { | |
| msgStack.push('TRACE:') | |
| trace.forEach(function (t) { | |
| msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function + '")' : '')) | |
| }) | |
| } | |
| console.log(msgStack.join('\n')) | |
| return true | |
| } | |
| phantom.onError = function (msg, trace) { | |
| var msgStack = ['ERROR: ' + msg] | |
| if (trace && trace.length) { | |
| msgStack.push('TRACE:') | |
| trace.forEach(function (t) { | |
| msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function + '")' : '')) | |
| }) | |
| } | |
| console.log(msgStack.join('\n')) | |
| return true | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment