cuprite icon indicating copy to clipboard operation
cuprite copied to clipboard

Skip injecting extensions on frame switch to prevent javascript errors

Open hoffi opened this issue 3 years ago • 2 comments

Fixes #200.

The extensions were injected again on every frame switch. That seemed unnecessary to me as they were already injected on page load by ferrum. This resulted in some javascript errors, because some constants were redefined by the default cuprite extension.

This change fixes this problem and there does not seem to be anything missing inside the frames.

hoffi avatar Jun 24 '22 12:06 hoffi

This was exactly the issue in the past as they weren't injected, in other words this is a workaround, I'll double check if Chrome fixed this.

Seems like this test isn't accurate because it doesn't check if there are extensions available in the frame.

route avatar Nov 19 '22 06:11 route

Any info on this?

Or should this be handled in ferrum? We could track all loaded extensions there and only execute them when they are not in the list. Something like this here and here:

extension_digest = Digest::SHA256.hexdigest(extension)
extension_wrapper = <<~JS
  window._ferrum_loaded_extensions ||= [];
  if (window._ferrum_loaded_extensions.indexOf("#{extension_digest}") == -1) {
    window._ferrum_loaded_extensions.push("#{extension_digest}");
    #{extension}
  }
JS
command("Page.addScriptToEvaluateOnNewDocument", source: extension_wrapper)
[...]

hoffi avatar Jan 17 '24 14:01 hoffi