Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not choke on PDF specs #1435

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/browserlib/get-title.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/**
* Gets the title of the document
*/
export default function () {
export default function (spec) {
const title = window.document.querySelector('title');
if (title) {
return title.textContent.replace(/\s+/g, ' ').trim();
}
else if (spec?.title) {
return spec.title;
}
else {
return '[No title found for ' + window.location.href + ']';
}
Expand Down
13 changes: 13 additions & 0 deletions src/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,19 @@ async function processSpecification(spec, processFunction, args, options) {
return;
}

// Puppeteer does not support loading PDF files and we would
// not know how to parse them in any case. Let's return an
// empty HTML page instead.
if (/\.pdf$/i.test(request.url)) {
await cdp.send('Fetch.fulfillRequest', {
requestId,
responseCode: 200,
responseHeaders: [{ name: 'Content-Type', value: 'text/html' }],
body: ''
});
return;
}

// Abort network requests that return a "stream", they won't
// play well with Puppeteer's "networkidle0" option, and our
// custom "fetch" function does not handle streams in any case
Expand Down
2 changes: 1 addition & 1 deletion tests/crawl.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ if (global.describe && describe instanceof Function) {
forceLocalFetch: true
});
const results = require(path.resolve(output, 'index.json'));
assert.equal(refResults.title, results.results[0].title);
assert.equal(results.results[0].title, 'Accelerometer');
});

it("matches spec series shortnames", async () => {
Expand Down