cuprite
cuprite copied to clipboard
Skip injecting extensions on frame switch to prevent javascript errors
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.
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.
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)
[...]