question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Snapshot images as base64

See original GitHub issue

Hi!

First of all awesome project, thanks for making it public!

I have a question regarding saving images offline as base64, but also keeping the original URL link. Right now an image is stored something like:

{'type': 2,
 'tagName': 'img',
 'attributes': {'id': 'mainImage', 'src': 'https://whatever.com/something.gif'},
 'childNodes': [],
 'id': 29},

Ideally the image content would be stored somewhere in there like: src="data:image/gif;base64,deadbeef ...

There’s an option to save the canvas like that.

Is it possible for the images as well?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
champkehcommented, Nov 17, 2021

Oh, I see what you mean,you can create a global canvas element as a render service, then in serializeNode function add follow code:

const canvasService: HTMLCanvasElement = document.createElement('canvas');
const canvasCtx: CanvasRenderingContext2D | null = canvasService.getContext('2d');

function serializeNode(n, options) {

  // ...

  // convert image to base64
  if (tagName === 'img' && canvasCtx) {
    canvasService.width = (n as HTMLImageElement).naturalWidth;
    canvasService.height = (n as HTMLImageElement).naturalHeight;
    canvasCtx.drawImage((n as HTMLImageElement), 0, 0);
    attributes.rr_dataURL = canvasService.toDataURL();
  }

  // ...
}

and i test that in local environment, result is follow, it seems feasible:

image

1reaction
champkehcommented, Nov 15, 2021

This could be cause result storage very big. My current method is to store images separately in Minio based on their content hash at project build time, then in the playback phase, dynamically proxy the address of the image to Minio’s url.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Capture a screenshot and convert it into a base64 String
Capturing a desktop image and converting data into base64 are entirely separate things. – Jon Skeet. May 26, 2017 at 15:26. Can you ......
Read more >
Get Base64 Encode String of Screenshot with Markups
sData is a Base64 encoding string. The customer copied the string to some online tool to verify the image, e.g..
Read more >
Attach screenshot/Base64 format on test failure to emailable ...
Also learn how to attach emailable extent report by attaching Base64 format of image / screenshot. Selenium java complete series ...
Read more >
5.0.5 - Attaching screenshot as Base64 String to Report - Part VII
In this video, we will cover1. Take a screenshot as png , jpg file and attach to report2. Take a screenshot as png...
Read more >
JSON Base64 Encoded Image - Add Screenshots
Return screenshot images in JSON format with a base64 encoding. Using the JSON format is a popular option when dealing with Rest APIs...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found