Skip to content

Commit e320908

Browse files
authored
don't fail crawl if profile can not be saved (#939)
- log exception caught from saving profile, log as error - bump to 1.10.2
1 parent df26169 commit e320908

2 files changed

Lines changed: 56 additions & 50 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "browsertrix-crawler",
3-
"version": "1.10.1",
3+
"version": "1.10.2",
44
"main": "browsertrix-crawler",
55
"type": "module",
66
"repository": "https://github.com/webrecorder/browsertrix-crawler",

src/util/browser.ts

Lines changed: 55 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -317,63 +317,69 @@ export class Browser {
317317

318318
logger.info("Saving Browser Profile");
319319

320-
// First, determine valid local path
321-
// can't save to http/https, so use default local path
322-
if (
323-
localFilename &&
324-
(localFilename.startsWith("http:") ||
325-
localFilename.startsWith("https") ||
326-
localFilename.startsWith("@"))
327-
) {
328-
localFilename = "";
329-
}
320+
try {
321+
// First, determine valid local path
322+
// can't save to http/https, so use default local path
323+
if (
324+
localFilename &&
325+
(localFilename.startsWith("http:") ||
326+
localFilename.startsWith("https") ||
327+
localFilename.startsWith("@"))
328+
) {
329+
localFilename = "";
330+
}
330331

331-
if (localFilename && !localFilename.startsWith("/")) {
332-
localFilename = path.resolve("/crawls/profiles/", localFilename);
333-
logger.info(
334-
`Absolute path for filename not provided, saving to ${localFilename}`,
335-
"browser",
336-
);
337-
}
332+
if (localFilename && !localFilename.startsWith("/")) {
333+
localFilename = path.resolve("/crawls/profiles/", localFilename);
334+
logger.info(
335+
`Absolute path for filename not provided, saving to ${localFilename}`,
336+
"browser",
337+
);
338+
}
338339

339-
const profileFilename = localFilename || "/crawls/profiles/profile.tar.gz";
340+
const profileFilename =
341+
localFilename || "/crawls/profiles/profile.tar.gz";
340342

341-
const outputDir = path.dirname(profileFilename);
342-
if (outputDir && !fs.existsSync(outputDir)) {
343-
fs.mkdirSync(outputDir, { recursive: true });
344-
}
343+
const outputDir = path.dirname(profileFilename);
344+
if (outputDir && !fs.existsSync(outputDir)) {
345+
fs.mkdirSync(outputDir, { recursive: true });
346+
}
345347

346-
logger.info("Local profile saved", { profileFilename }, "browser");
347-
child_process.execFileSync("tar", ["cvfz", profileFilename, "./"], {
348-
cwd: this.profileDir,
349-
});
348+
logger.info("Local profile saved", { profileFilename }, "browser");
349+
child_process.execFileSync("tar", ["cvfz", profileFilename, "./"], {
350+
cwd: this.profileDir,
351+
});
350352

351-
let resource: UploadResult | null = null;
353+
let resource: UploadResult | null = null;
352354

353-
// Only storage relative remote path supported
354-
if (remoteFilename && storage) {
355-
// remote storage relative prefix, always storage relative here
356-
if (remoteFilename.startsWith("@")) {
357-
remoteFilename = remoteFilename.slice(1);
358-
}
359-
if (
360-
remoteFilename.startsWith("http:") ||
361-
remoteFilename.startsWith("https:") ||
362-
remoteFilename.startsWith("/")
363-
) {
364-
logger.warn(
365-
"Not saving remote profile, invalid target",
366-
{ remoteFilename },
367-
"browser",
368-
);
369-
} else {
370-
logger.info("Uploading to remote storage...", {}, "browser");
371-
resource = await storage.uploadFile(profileFilename, remoteFilename);
355+
// Only storage relative remote path supported
356+
if (remoteFilename && storage) {
357+
// remote storage relative prefix, always storage relative here
358+
if (remoteFilename.startsWith("@")) {
359+
remoteFilename = remoteFilename.slice(1);
360+
}
361+
if (
362+
remoteFilename.startsWith("http:") ||
363+
remoteFilename.startsWith("https:") ||
364+
remoteFilename.startsWith("/")
365+
) {
366+
logger.warn(
367+
"Not saving remote profile, invalid target",
368+
{ remoteFilename },
369+
"browser",
370+
);
371+
} else {
372+
logger.info("Uploading to remote storage...", {}, "browser");
373+
resource = await storage.uploadFile(profileFilename, remoteFilename);
374+
}
372375
}
373-
}
374376

375-
logger.info("Profile creation done", {}, "browser");
376-
return resource;
377+
logger.info("Profile creation done", {}, "browser");
378+
return resource;
379+
} catch (e) {
380+
logger.error("Unable to save profile after crawl", e, "browser");
381+
return null;
382+
}
377383
}
378384

379385
chromeArgs({

0 commit comments

Comments
 (0)