Giter VIP home page Giter VIP logo

sidecar-browsershot's People

Contributors

aarondfrancis avatar admiral-enigma avatar ahinkle avatar bryanjamesmiller avatar dependabot[bot] avatar freekmurze avatar github-actions[bot] avatar jrslv avatar loots-it avatar marksalmon avatar orkhanahmadov avatar osbre avatar princejohnsantillan avatar robgaskell avatar silver343 avatar stefanzweifel avatar yoeriboven avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

sidecar-browsershot's Issues

TargetCloseError: Protocol error (Page.printToPDF): Target closed

Since upgrading to version > 1.9.1 we have frequently been getting one of the following exceptions when attempting to generate PDF's using the package:

Error: Command failed: node ./browser.cjs '-f file:///tmp/browsershot.js' TargetCloseError: Protocol error (Page.printToPDF): Target closed at CallbackRegistry.clear (/opt/nodejs/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:146:36)

Error: Command failed: node ./browser.cjs '-f file:///tmp/browsershot.js' ProtocolError: Page.printToPDF timed out. Increase the 'protocolTimeout' setting in launch/connect calls for a higher timeout if needed. at <instance_members_initializer> (/opt/nodejs/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:49:14)

I have since downgraded back to v1.9.1 and the exceptions have all stopped happening.

Any idea what could be causing these problems and how to overcome them?

I have tried to find and configure the protocolTimeout setting as suggested in the exception message but I couldn't find any information to help with this, so either my attempts to set it were wrong or were unsuccessful as a solution as whatever I tried made no difference to the outcome.

encoding differs

I am creating a base64pdf and passing it to Spatie's media library, it fails as decoding and reencoding do not match, it works when running browserShot locally.

it seems that the encode pdf returned uses a different encoder.

Sorry there's not much detail.

Corrupted PDF on production, fine on local

Hey there,

I've been using this package for a while now and today, I've noticed that when I generate a PDF from my local dev env, it works fine, however as soon as I generate it from prod, it generated a 2MB PDF file (instead of 540KB), and is corrupted.
Both are running on AWS just fine...

Wondering what I could do to diagnose this? Here is attached the corrupted PDF.
carte-CC7972778.pdf
Mime type of it tells me application/octet-stream...

Deprecated Node Runtime

We are contacting you as we have identified that your AWS Account currently has one or more Lambda functions using the Node.js 14 runtime.

We are ending support for Node.js 14 in AWS Lambda. This follows Node.js 14 End-Of-Life (EOL) reached on April 30, 2023 [1].

As described in the Lambda runtime support policy [2], end of support for language runtimes in Lambda happens in two stages. Starting November 27, 2023, Lambda will no longer apply security patches and other updates to the Node.js 14 runtime used by Lambda functions, and functions using Node.js 14 will no longer be eligible for technical support. In addition, you will no longer be able to create new Lambda functions using the Node.js 14 runtime. Starting January 25, 2024, you will no longer be able to update existing functions using the Node.js 14 runtime.

We recommend that you upgrade your existing Node.js 14 functions to Node.js 18 before November 27, 2023.

Unable to install using Laravel 11

Thanks for the new release on Laravel 11. I'm seeing the following issue when trying to upgrade to 2.3.0:

wnx/sidecar-browsershot v2.3.0 requires hammerstone/sidecar ^0.4.0 -> satisfiable by hammerstone/sidecar[v0.4.0, v0.4.1, v0.4.2].

hammerstone/sidecar[v0.4.0, ..., v0.4.2] require illuminate/support ^8.0|^9.0|^10 -> found illuminate/support[v8.0.0, ..., 8.x-dev, v9.0.0-beta.1, ..., 9.x-dev, v10.0.0, ..., 10.x-dev] but these were not loaded, likely because it conflicts with another require.

I thought ^0.4.0 would be supportive of Sidecar v0.5.0 but maybe I'm mistaken. Any ideas here?

Thanks so much!

For some reason Chrome did not write a file at `example.pdf`

Thank you for this awesome package.

The solution as mentioned here and here is to use a compatible version of node and puppeteer.

Changing the layer version for chrome-aws-lambda-layer in the config/sidecar-browsershot.php to the latest (in my case 45) worked out fine for my case.

Hope you can update the default version whenever you do a new release. Cheers.

Invoke Error 429

Hi there,

We seem to be receiving error 429 exceptions semi-frequently from our browsershot lambda function.

There are no throttle metrics from the function, however from the cloudwatch logs we receive:

Invoke Error 	
{
    "errorType": "Error",
    "errorMessage": "Unexpected status code: 429.",
    "stack": [
        "Error: Unexpected status code: 429.",
        "    at intoError (/var/runtime/Errors.js:27:12)",
        "    at postError (/var/runtime/CallbackContext.js:21:47)",
        "    at done (/var/runtime/CallbackContext.js:59:7)",
        "    at fail (/var/runtime/CallbackContext.js:71:7)",
        "    at /var/runtime/CallbackContext.js:113:16",
        "    at processTicksAndRejections (internal/process/task_queues.js:95:5)"
    ]
}

chrome-aws-lambda layer is arn:aws:lambda:eu-west-2:764866452798:layer:chrome-aws-lambda:31 on NodeJS 14.x

Thanks,
Scott

Loading never stop

Discussed in #75

Originally posted by luxorwannabe June 21, 2023
Hi, first of all thank you for sidecar-browsershot...

I have successfully installed it and have it connected to S3 Buckets, I found one zip with random name there, also I can see the sc-lamdabrowsershot-production-browsershot function listed in Lamba Functions.
But when I try to run it the browser keeps loading never stop (almost 5 minutes) and ends up with the 503 timeout gateway...

Can you help me with this? Thanks

Function `browsershot` not found in environment `staging`

wherever I did , always get this issue .
Hammerstone\Sidecar\Exceptions\FunctionNotFoundException: Functionbrowsershotnot found in environmentstaging. It may exist other environments, you may need to overwrite the environment while deploying to staging`. See https://hammerstone.dev/sidecar/docs/main/functions/deploying#faking-the-environment for more information. in /var/app/current/vendor/hammerstone/sidecar/src/Exceptions/FunctionNotFoundException.php:23 Stack trace: #0 /var/app/current/vendor/hammerstone/sidecar/src/Manager.php(102): Hammerstone\Sidecar\Exceptions\FunctionNotFoundException::make(Object(Wnx\SidecarBrowsershot\Functions\BrowsershotFunction)) #1

`

and :

[Sidecar] Deploying Wnx\SidecarBrowsershot\Functions\BrowsershotFunction to Lambda assc-laravel-staging-browsershot`.
↳ Environment: staging
↳ Architecture: x86_64
↳ Package Type: Zip
↳ Runtime: nodejs18.x
↳ Function already exists, potentially updating code and configuration.
↳ Packaging files for deployment.
↳ Package unchanged. Reusing s3://sidecar-space-staging/sidecar/001-a40f37a8be6fb0212ebf7a5703d53b.zip.
↳ Function code and configuration are unchanged. Not updating anything.
[Sidecar] Activating function Wnx\SidecarBrowsershot\Functions\BrowsershotFunction.
↳ Environment variables not managed by Sidecar. Skipping.
↳ Version 2 of sc-laravel-staging-browsershot is already active.

`

from aws lambda :
image

Generated pdf contains [object Object]

Since v1.10.0, pdf's generated from a file stored in s3 will generate a pdf that contains only the text:

"[object Object]"

I have been using the following code to see the problem.

        $html = BrowsershotLambda::url('https://example.com')->bodyHtml();
        Storage::disk('s3')->put('html/example.html', $html);
        BrowsershotLambda::readHtmlFromS3('html/example.html')->save('example.pdf');

UnsuccessfulResponse exception is not thrown when using preventUnsuccessfulResponse method

In the Spatie browsershot package, when using preventUnsuccessfulResponse method, it will throw UnsuccessfulResponse exception:

$browsershot->preventUnsuccessfulResponse($this->preventUnsuccessfulResponse);

But in this package, it throws Hammerstone\Sidecar\Exceptions\LambdaExecutionException, so it is hard to detect if a URL has HTTP error respond code like 404, 500, etc. Is it possible to throw UnsuccessfulResponse in Lambda environment?

Thank you!

Times out when creating screenshots

image

I just upgraded everything to be on the latest (also using node20) because it was failing on the node18 (using the previous version of this function)

Already tried with several things but no luck, this is the code:

$base64Screenshot = Browsershot::url($temporarySignedUrl)
            ->select('#graphContainer')
            ->windowSize((int) round((int) $this->data->width), (int) round((int) $this->data->height))
            ->waitForSelector('#graphContainer')
            ->setExtraHttpHeaders([
                'ngrok-skip-browser-warning' => '69420',
            ])
            ->waitUntilNetworkIdle(false)
            ->noSandbox()
            ->base64Screenshot();

file_get_contents(/var/task/vendor/spatie/browsershot/bin/browser.js): Failed to open stream: No such file or directory

I just upgraded to the latest version and get this error when deploying on Vapor

Hook: sidecar:deploy --activate
[Sidecar] Deploying App\Sidecar\Functions\BrowsershotFunction to Lambda as `SC-Project-production-browsershot`.
          ↳ Environment: production
          ↳ Architecture: x86_64
          ↳ Package Type: Zip
          ↳ Runtime: nodejs14.x
          ↳ Function already exists, potentially updating code and configuration.

In BrowsershotFunction.php line 45:
                                                                               
  file_get_contents(/var/task/vendor/spatie/browsershot/bin/browser.js): Failed to open stream: No such file or directory

Error: Navigating frame was detached at #onFrameDetached

Hi,

From today I've suddenly been experiencing this error:
Lambda Execution Exception for Wnx\SidecarBrowsershot\Functions\BrowsershotFunction: "Command failed: node ./browser.cjs '-f file:///tmp/browsershot.js' Error: Navigating frame was detached at #onFrameDetached (/opt/nodejs/node_modules/puppeteer-core/lib/cjs/puppeteer/common/LifecycleWatcher.js:110:47) at /opt/nodejs/node_modules/puppeteer-core/lib/cjs/third_party/mitt/index.js:1:269 at Array.map () at Object.emit (/opt/nodejs/node_modules/puppeteer-core/lib/cjs/third_party/mitt/index.js:1:252) at CDPFrame.emit (/opt/nodejs/node_modules/puppeteer-core/lib/cjs/puppeteer/common/EventEmitter.js:88:22) at #removeFramesRecursively (/opt/nodejs/node_modules/puppeteer-core/lib/cjs/puppeteer/common/FrameManager.js:448:15) at #onClientDisconnect (/opt/nodejs/node_modules/puppeteer-core/lib/cjs/puppeteer/common/FrameManager.js:114:42) . [TRACE] Error: Command failed: node ./browser.cjs '-f file:///tmp/browsershot.js' Error: Navigating frame was detached at #onFrameDetached (/opt/nodejs/node_modules/puppeteer-core/lib/cjs/puppeteer/common/LifecycleWatcher.js:110:47)".

Using:

  • PHP 8.2
  • "spatie/pdf-to-image": "^2.2"
  • "wnx/sidecar-browsershot": "^1.1"
  • "hammerstone/sidecar": "^0.4"
  • "spatie/browsershot": "^3.57".

Thanks

Emoji CDN sometimes return 429

This line sometimes fail because the CDN returns a 429 Too many request.
await chromium.font('https://raw.githack.com/googlei18n/noto-emoji/master/fonts/NotoColorEmoji.ttf');

Is there some way to change this url in a config, so that we can self host the font? Or maybe the package needs to use a different CDN.

Is there any benefit from loading the font file during cold boot rather than just including it in the lambda bundle?

Lambda execution randomly times out

We never had this issue with v1, but since upgrading to v2, the following exception getting thrown randomly when trying to generate a PDF:

Lambda Execution Exception for Wnx\SidecarBrowsershot\Functions\BrowsershotFunction: Task timed out after 300.11 seconds.

I saw another reported issue with #100, but that one seems to be related to protocol timeout, this one is related to Lambda's 30-second timeout. Also unlike #100, we don't try to generate huge PDFs. It is a single-page PDF page and it doesn't always fail but is completely random. Fails once then trying again it succeeds.

Any clues? Anything in v2 that can make lambda substantially longer to execute?

No space left on device

I notice that this error will occur when I run with high concurrency (many browser instances). Does the tmp data from the puppeteer is saved in /tmp. If it does then weird because the tmp folder can allow 10GB.

This is the error I got:

Hammerstone\Sidecar\Exceptions\LambdaExecutionException
Lambda Execution Exception for Wnx\SidecarBrowsershot\Functions\BrowsershotFunction: "Command failed: node ./browser.js '-f file:///tmp/browsershot.js'
[Error: ENOSPC: no space left on device, mkdtemp '/tmp/puppeteer_dev_chrome_profile-1WPNyY'] {
  errno: -28,
  code: 'ENOSPC',
  syscall: 'mkdtemp',
  path: '/tmp/puppeteer_dev_chrome_profile-1WPNyY'
}
. [TRACE] Error: Command failed: node ./browser.js '-f file:///tmp/browsershot.js' [Error: ENOSPC: no space left on device, mkdtemp '/tmp/puppeteer_dev_chrome_profile-1WPNyY'] { errno: -28,".

Another exception I got is about: Error: net::ERR_INSUFFICIENT_RESOURCES

Hammerstone\Sidecar\Exceptions\LambdaExecutionException
Lambda Execution Exception for Wnx\SidecarBrowsershot\Functions\BrowsershotFunction: "Command failed: node ./browser.js '-f file:///tmp/browsershot.js'
Error: net::ERR_INSUFFICIENT_RESOURCES at https://var.recreplanet.fr/rollergliss-la-garde-piste-roller-famille-patin-roulette-83
    at navigate (/opt/nodejs/node_modules/puppeteer-core/lib/cjs/puppeteer/common/FrameManager.js:164:23)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async FrameManager.navigateFrame (/opt/nodejs/node_modules/puppeteer-core/lib/cjs/puppeteer/common/FrameManager.js:141:21)
    at async Frame.goto (/opt/nodejs/node_modules/puppeteer-core/lib/cjs/puppeteer/common/FrameManager.js:541:16)
    at async Page.goto (/opt/nodejs/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Page.js:1200:16)
    at async callChrome (/var/task/browser.js:251:26)
. [TRACE] Error: Command failed: node ./browser.js '-f file:///tmp/browsershot.js' Error: net::ERR_INSUFFICIENT_RESOURCES at https://var.recreplanet.fr/rollergliss-la-garde-piste-roller-famille-patin-roulette-83 at navigate (/opt/nodejs/node_modules/puppeteer-core/lib/cjs/puppeteer/common/FrameManager.js:164:23)".

I read this mifi/reactive-video#11 and seems this exception is also about the disk space or memory. I tried to increase the memory of the lambda function to see if this exception come back or not. I will report later.

Font issue

There is a difference between the default fonts that are used in sidecar-browsershot and browsershot.

Small example:

        $pdfString = Browsershot::html($html)
            ->margins(18, 18, 18, 18)
            ->format('A4')
            ->pdf();

The html:

<!DOCTYPE html>
<html>
<body>
  <h1>Invoice</h1>
</body>
</html>

The outcome in sidecar-browsershot:
invoice-aws.pdf

The outcome in browsershot:
invoice.pdf

In retrospective, it wasn't a great idea of me to not specify a font in the first place. But it seems that font support is not the same in sidecar-browsershot as in browsershot. I could probable use a font-face but I want to use a local one. Maybe it's an idea to add such an option to sidecar-browsershot? If I create a pull request for this, would this be considered?

sidecar-deployment-user is not authorized to perform: lambda:GetLayerVersion in me-south-1

this happens only in me-south-1 region , it works fine in us-west-2

when run : php artisan sidecar:deploy --activate

AccessDeniedException (client): User: arn:aws:iam::**:user/sidecar-deployment-user is not authorized to perform: lambda:GetLayerVersion on resource: arn:aws:lambda:me-south-1:821527532446:layer:sidecar-browsershot-layer:1 because no resource-based policy allows the lambda:GetLayerVersion action - {"Message":"User: arn:aws:iam::13286269**944:user/sidecar-deployment-user is not authorized to perform: lambda:GetLayerVersion on resource: arn:aws:lambda:me-south-1:821527532446:layer:sidecar-browsershot-layer:1 because no resource-based policy allows the lambda:GetLayerVersion action"}

the user policy :

`

"Version": "2012-10-17",
"Statement": [
	{
		"Sid": "VisualEditor0",
	"Effect": "Allow",
		"Action": "iam:PassRole",
		"Resource": "*",
		"Condition": {
			"StringEquals": {
				"iam:PassedToService": "lambda.amazonaws.com"
			}
	}
	},
	{
		"Sid": "VisualEditor1",
		"Effect": "Allow",
		"Action": [
			"states:*",
			"ecr:SetRepositoryPolicy",
			"lambda:*",
			"ecr:GetRepositoryPolicy"
		],
		"Resource": "*"
	},
	{
		"Sid": "VisualEditor2",
		"Effect": "Allow",
		"Action": [
			"logs:DescribeLogStreams",
			"logs:GetLogEvents",
			"logs:FilterLogEvents"
		],
		"Resource": "arn:aws:logs:*:*:log-group:/aws/lambda/*"
	},
	{
		"Sid": "VisualEditor3",
		"Effect": "Allow",
		"Action": "s3:*",
		"Resource": [
			"arn:aws:s3:::sidecar-*",
			"arn:aws:s3:::sidecar-*/*",
			"arn:aws:s3:::*"
		]
	}
]

`

Error: Navigating frame was detached

I'm getting a weird error while trying to generate a PDF:

Lambda Execution Exception for Wnx\SidecarBrowsershot\Functions\BrowsershotFunction: "Command failed: node ./browser.cjs '-f file:///tmp/browsershot.js'
Error: Navigating frame was detached
    at #onFrameDetached (/opt/nodejs/node_modules/puppeteer-core/lib/cjs/puppeteer/common/LifecycleWatcher.js:110:47)
    at /opt/nodejs/node_modules/puppeteer-core/lib/cjs/third_party/mitt/index.js:1:269
    at Array.map (<anonymous>)
    at Object.emit (/opt/nodejs/node_modules/puppeteer-core/lib/cjs/third_party/mitt/index.js:1:252)
    at CDPFrame.emit (/opt/nodejs/node_modules/puppeteer-core/lib/cjs/puppeteer/common/EventEmitter.js:88:22)
    at #removeFramesRecursively (/opt/nodejs/node_modules/puppeteer-core/lib/cjs/puppeteer/common/FrameManager.js:448:15)
    at #onClientDisconnect (/opt/nodejs/node_modules/puppeteer-core/lib/cjs/puppeteer/common/FrameManager.js:114:42)
. [TRACE] Error: Command failed: node ./browser.cjs '-f file:///tmp/browsershot.js' Error: Navigating frame was detached at #onFrameDetached (/opt/nodejs/node_modules/puppeteer-core/lib/cjs/puppeteer/common/LifecycleWatcher.js:110:47)".

Here is the code that was working up until this morning:

        $pdf = BrowsershotLambda::html($html)
            ->showBackground()
            ->format("Letter")
            ->margins(10, 10, 5, 10)
            ->addChromiumArguments([
                "font-render-hinting" => "none",
                "force-color-profile" => "srgb",
            ])
            ->waitUntilNetworkIdle()
            ->pdf();

As a side note, it seems to coincide with another error that popped up this morning regarding available space in /tmp:

Lambda Execution Exception for Wnx\SidecarBrowsershot\Functions\BrowsershotFunction: "ENOSPC: no space left on device, write. [TRACE] Error: ENOSPC: no space left on device, write at Object.writeSync (node:fs:929:3) at Object.writeFileSync (node:fs:2328:26)".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.