diff --git a/src/api.ts b/src/api.ts index 7686f4bd..183f813d 100644 --- a/src/api.ts +++ b/src/api.ts @@ -239,10 +239,14 @@ export default class Chromeless implements Promise { selector?: string, options?: ScreenshotOptions, ): Chromeless { - if (typeof selector === 'object') { - options = selector - selector = undefined - } + // I am not sure why this code was here; it seems to be causing a bug + // where options can not be passed correctly (any options passed will be + // seen as a selector) + // + //if (typeof selector === 'object') { + // options = selector + // selector = undefined + //} this.lastReturnPromise = this.queue.process({ type: 'returnScreenshot', selector, diff --git a/src/chrome/local-runtime.ts b/src/chrome/local-runtime.ts index af1f7392..03fceba9 100644 --- a/src/chrome/local-runtime.ts +++ b/src/chrome/local-runtime.ts @@ -410,7 +410,7 @@ export default class LocalRuntime { const data = await screenshot(this.client, selector) if (isS3Configured()) { - return await uploadToS3(data, 'image/png') + return await uploadToS3(data, 'image/png', options && options.s3ObjectKeyPrefixOverride) } else { return writeToFile(data, 'png', options && options.filePath) } diff --git a/src/types.ts b/src/types.ts index 5f5c7f97..c65e30a3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -238,6 +238,7 @@ export interface PdfOptions { export interface ScreenshotOptions { filePath?: string + s3ObjectKeyPrefixOverride?: string //string to use as key when saving screenshots to s3 } export type Quad = Array diff --git a/src/util.ts b/src/util.ts index f46f9eb0..4c04e8f6 100644 --- a/src/util.ts +++ b/src/util.ts @@ -628,8 +628,9 @@ export async function uploadToS3( const s3ContentType = s3ContentTypes[contentType] if (!s3ContentType) { throw new Error(`Unknown S3 Content type ${contentType}`) - } - const s3Path = `${getS3ObjectKeyPrefix()}${cuid()}.${s3ContentType.extension}` + } + const s3Prefix = s3ObjectKeyPrefixOverride || `${getS3ObjectKeyPrefix()}` + const s3Path = `${s3Prefix}${cuid()}.${s3ContentType.extension}` const s3 = new AWS.S3() await s3 .putObject({