module Selenium::WebDriver::DriverExtensions::HasPinnedScripts

def pin_script(script)

def pin_script(script)
  script = DevTools::PinnedScript.new(script)
  pinned_scripts << script
  devtools.page.enable
  devtools.runtime.evaluate(expression: script.callable)
  response = devtools.page.add_script_to_evaluate_on_new_document(source: script.callable)
  script.devtools_identifier = response.dig('result', 'identifier')
  script
end

def pinned_scripts

def pinned_scripts
  @pinned_scripts ||= []
end

def unpin_script(script)

def unpin_script(script)
  devtools.runtime.evaluate(expression: script.remove)
  devtools.page.remove_script_to_evaluate_on_new_document(identifier: script.devtools_identifier)
  pinned_scripts.delete(script)
end