Chromeless: Can't set filePath for screenshots

Created on 7 Sep 2017  路  9Comments  路  Source: prisma-archive/chromeless

Hello, it seems setting filePath still saves the screenshot to the temp folder. I'm on Windows 10 using Node 8.4.0 and Chromeless 1.3.0.

My test:

import { Chromeless } from 'chromeless'
import { join } from 'path'

jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000

const chrome = new Chromeless({ viewport: { width: 1920, height: 1080 } })

describe('Chromeless example', () => {
  it('should create a screenshot', async () => {
    await chrome
      .goto('http://localhost:3000')
      .screenshot({ filePath: join(__dirname, 'screenshot.png') })

    await chrome.end()
  })
})

According to the docs you should be able to set the filePath like this but it doesn't seem to work.

Most helpful comment

I can confirm, if I compile chromeless myself the parameters are taken care of correctly, above method is compiled as

    Chromeless.prototype.screenshot = function (selector, options) {
        if (typeof selector === 'object') {
            options = selector;
            selector = undefined;
        }
        this.lastReturnPromise = this.queue.process({
            type: 'returnScreenshot',
            selector: selector,
            options: options,
        });
        return new Chromeless({}, this);
    };

So there seems to be something wrong with the package deployed to npm!

All 9 comments

+1

Not sure if it's the same issue, but how do I save a PDF to a filePath instead of the randomly generated filename?

same for selector parameter.

+1

I stepped through the code in the 1.3.0 release build and it looks like the parameters to .screenshot() are simply ignored:

    Chromeless.prototype.screenshot = function () {
        this.lastReturnPromise = this.queue.process({
            type: 'returnScreenshot',
        });
        return new Chromeless({}, this);
    };

(dist/src/api.js:185)

In the TypeScript code in the repo, however, the code passing on the arguments is present:

https://github.com/graphcool/chromeless/blob/7d931568e6d64f7ab74c8e54ba205d6164c1d979/src/api.ts#L221-L236

Maybe a problem in the TS build process or some old file that sneked into the release?

I can confirm, if I compile chromeless myself the parameters are taken care of correctly, above method is compiled as

    Chromeless.prototype.screenshot = function (selector, options) {
        if (typeof selector === 'object') {
            options = selector;
            selector = undefined;
        }
        this.lastReturnPromise = this.queue.process({
            type: 'returnScreenshot',
            selector: selector,
            options: options,
        });
        return new Chromeless({}, this);
    };

So there seems to be something wrong with the package deployed to npm!

still doesn't work

Has there been a more thorough look into this. @floledermann et al. are completely correct that the params are not passed in the code from npm. I just wanted to clarify that this isn't just in the api.js/.ts files, but also in the local-runtime.js/.ts file. In the version from npm, it passes it as

case 'returnScreenshot':
             return [2 /*return*/, this.returnScreenshot()];

and the actual method is missing it too (#Line 551). Simply passing the command option all the way through (i.e. fixing api.js and local-runtime.js) and then referencing it as
filePath = command.options.filePath || path.join(os.tmpdir(), cuid() + ".png"); is currently my workaround.

v1.4 released on NPM mid December should have resolved this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ovheurdrive picture ovheurdrive  路  5Comments

maruidea picture maruidea  路  6Comments

schickling picture schickling  路  5Comments

adieuadieu picture adieuadieu  路  3Comments

schickling picture schickling  路  3Comments