Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not update element data #3166

Open
1 of 2 tasks
nodvick opened this issue Apr 18, 2024 · 1 comment
Open
1 of 2 tasks

Does not update element data #3166

nodvick opened this issue Apr 18, 2024 · 1 comment

Comments

@nodvick
Copy link

nodvick commented Apr 18, 2024

Please follow the general troubleshooting steps first:

  • You are using the latest version
  • You are testing using the non-minified version of html2canvas and checked any potential issues reported in the console

Bug reports:

If you change an element's value in the desired section to screenshot, then press a button to call the html2canvas function, the screenshot will be the old value.

neither

var ae = document.activeElement;
ae.setAttribute("value", ae.value + ae.getAttribute("data-text"));

or

document.activeElement.blur();

before calling so that the focus is changed in an attempt to sync the value attribute to the value property does not prevent this issue.

Specifications:

  • html2canvas version tested with: 1.4.1.min
  • Browser & version: firefox 124.0.2 64-bit & safari on iphone
  • Operating system: Windows 11, IOS 17
@nodvick
Copy link
Author

nodvick commented Apr 19, 2024

More details and fix:

I was using the canvas.todataurl string as data to submit, then processing/converting/saving without ever actually putting the canvas on the page anywhere. appendchild(canvas) screenshotdata = canvas.todaturl(), then removechild(canvas) fixes it, with in my edge case because there were so many many elements its cloning, it is also a timing issue, async then await the function to generate screenshot, await the canvas creation, then submit the data was also required

(

async function getSS() {
			
			if(o('TEST')!=null) document.body.removeChild(o('TEST'));
			
			await html2canvas(document.body).then(
			function (c) {
				c.id="TEST";
				document.body.appendChild(c);
				
			});
			
			o('screenshotData').value = o('TEST').toDataURL();
			
			document.body.removeChild(o('TEST'));
			
			return true;
		}
////---later
		async function SubmitNotes(e) {
			e.preventDefault();
			await getSS();

EDIT: o() is sort of my fingerprint, you see it in almost every single javascript thing I do, sorry, for reference:
function o(obj) { return document.getElementById(obj); }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant