Implement a new typescript version that uses Puppeteer #192
Conversation
src/renderer.ts
Outdated
* Injects a <base> tag which allows other resources to load. This | ||
* has no effect on serialised output, but allows it to verify render | ||
* quality. | ||
* @param {string} url - Requested URL to set as the base. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can omit the {type} since it's already in the typescript signature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/renderer.ts
Outdated
|
||
// Navigate to page. | ||
const response = | ||
await page.goto(url, {waitUntil: 'networkidle0'}).catch(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why networkidle0 vs 1 etc.?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a puppeteer option to wait until there are no outstanding network requests.
src/renderer.ts
Outdated
// Navigate to page. | ||
const response = | ||
await page.goto(url, {waitUntil: 'networkidle0'}).catch(() => { | ||
return undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment about why it's ok to ignore exceptions here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comment. Not really ignoring though, captured in the next if if
statement.
const newStatusCode = | ||
await page | ||
.$eval( | ||
'meta[name="render:status_code"]', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment about what's going on here with this meta tag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/renderer.ts
Outdated
'meta[name="render:status_code"]', | ||
(element) => parseInt(element.getAttribute('content') || '')) | ||
.catch(() => undefined); | ||
// Treat 304 Not Modified as 200 OK. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presumably you have the body here because pupeteer gives you the cached response? Just note that in the comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you mean; will update comment. Chrome will give you a 304 when you revisit the site and its using browser cache.
src/renderer.ts
Outdated
status: number; content: string; | ||
} | ||
|
||
export class Renderer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
brief description
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/rendertron.ts
Outdated
} | ||
} | ||
|
||
restricted(href: string): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/test/app-test.ts
Outdated
const app = express(); | ||
app.use(express.static(path.resolve(__dirname, '../../test-resources'))); | ||
|
||
// const appInstances:express.Express[] = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops fixed.
src/test/app-test.ts
Outdated
await rendertron.initialize(false); | ||
await app.listen(1234); | ||
}); | ||
// async function createServer() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@aomarks PTAL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
No description provided.