Module: Puppeteer::Bidi::CookieUtils
- Defined in:
- lib/puppeteer/bidi/cookie_utils.rb,
sig/puppeteer/bidi/cookie_utils.rbs
Constant Summary collapse
- CDP_SPECIFIC_PREFIX =
"goog:"
Class Method Summary collapse
- .bidi_to_puppeteer_cookie(bidi_cookie, return_composite_partition_key: false) ⇒ Hash[String, untyped]
- .cdp_specific_cookie_properties_from_bidi(cookie, *property_names) ⇒ Hash[String, untyped]
- .cdp_specific_cookie_properties_from_puppeteer_to_bidi(cookie, *property_names) ⇒ Hash[String, untyped]
- .convert_cookies_expiry_cdp_to_bidi(expiry) ⇒ Numeric?
- .convert_cookies_partition_key_from_puppeteer_to_bidi(partition_key) ⇒ String?
- .convert_cookies_same_site_bidi_to_cdp(same_site) ⇒ String
- .convert_cookies_same_site_cdp_to_bidi(same_site) ⇒ String?
- .normalize_cookie_input(cookie) ⇒ Hash[String, untyped]
- .partition_key_from_bidi(partition_key, return_composite_partition_key) ⇒ Hash[String, untyped]
- .test_url_match_cookie(cookie, normalized_url) ⇒ Boolean
- .test_url_match_cookie_hostname(cookie, normalized_url) ⇒ Boolean
- .test_url_match_cookie_path(cookie, normalized_url) ⇒ Boolean
Class Method Details
.bidi_to_puppeteer_cookie(bidi_cookie, return_composite_partition_key: false) ⇒ Hash[String, untyped]
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/puppeteer/bidi/cookie_utils.rb', line 18 def self.(, return_composite_partition_key: false) value = ["value"] value = value["value"] if value.is_a?(Hash) expiry = ["expiry"] partition_key = ["#{CDP_SPECIFIC_PREFIX}partitionKey"] = { "name" => ["name"], "value" => value, "domain" => ["domain"], "path" => ["path"], "size" => ["size"], "httpOnly" => ["httpOnly"], "secure" => ["secure"], "sameSite" => (["sameSite"]), "expires" => expiry.nil? ? -1 : expiry, "session" => expiry.nil? || expiry <= 0, }.compact .merge!((, "sourceScheme", "partitionKeyOpaque", "priority")) .merge!(partition_key_from_bidi(partition_key, return_composite_partition_key)) end |
.cdp_specific_cookie_properties_from_bidi(cookie, *property_names) ⇒ Hash[String, untyped]
113 114 115 116 117 118 119 120 |
# File 'lib/puppeteer/bidi/cookie_utils.rb', line 113 def self.(, *property_names) property_names.each_with_object({}) do |property, result| key = "#{CDP_SPECIFIC_PREFIX}#{property}" next unless .key?(key) result[property] = [key] end end |
.cdp_specific_cookie_properties_from_puppeteer_to_bidi(cookie, *property_names) ⇒ Hash[String, untyped]
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/puppeteer/bidi/cookie_utils.rb', line 99 def self.(, *property_names) property_names.each_with_object({}) do |property, result| next unless .key?(property) value = [property] next if value.nil? result["#{CDP_SPECIFIC_PREFIX}#{property}"] = value end end |
.convert_cookies_expiry_cdp_to_bidi(expiry) ⇒ Numeric?
77 78 79 80 81 |
# File 'lib/puppeteer/bidi/cookie_utils.rb', line 77 def self.(expiry) return nil if expiry.nil? || expiry == -1 expiry end |
.convert_cookies_partition_key_from_puppeteer_to_bidi(partition_key) ⇒ String?
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/puppeteer/bidi/cookie_utils.rb', line 85 def self.(partition_key) return partition_key if partition_key.nil? || partition_key.is_a?(String) normalized = (partition_key) if normalized["hasCrossSiteAncestor"] raise UnsupportedOperationError, "WebDriver BiDi does not support `hasCrossSiteAncestor` yet." end normalized["sourceOrigin"] end |
.convert_cookies_same_site_bidi_to_cdp(same_site) ⇒ String
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/puppeteer/bidi/cookie_utils.rb', line 47 def self.(same_site) case same_site when "strict" "Strict" when "lax" "Lax" when "none" "None" else "Default" end end |
.convert_cookies_same_site_cdp_to_bidi(same_site) ⇒ String?
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/puppeteer/bidi/cookie_utils.rb', line 62 def self.(same_site) case same_site when "Strict" "strict" when "Lax" "lax" when "None" "none" else "default" end end |
.normalize_cookie_input(cookie) ⇒ Hash[String, untyped]
11 12 13 |
# File 'lib/puppeteer/bidi/cookie_utils.rb', line 11 def self.() .transform_keys(&:to_s) end |
.partition_key_from_bidi(partition_key, return_composite_partition_key) ⇒ Hash[String, untyped]
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/puppeteer/bidi/cookie_utils.rb', line 168 def self.partition_key_from_bidi(partition_key, return_composite_partition_key) return {} if partition_key.nil? if partition_key.is_a?(String) return { "partitionKey" => partition_key } end return {} unless partition_key.is_a?(Hash) normalized = (partition_key) top_level_site = normalized["topLevelSite"] has_cross_site_ancestor = normalized["hasCrossSiteAncestor"] if return_composite_partition_key return { "partitionKey" => { "sourceOrigin" => top_level_site, "hasCrossSiteAncestor" => has_cross_site_ancestor.nil? ? false : has_cross_site_ancestor, }, } end { "partitionKey" => top_level_site } end |
.test_url_match_cookie(cookie, normalized_url) ⇒ Boolean
125 126 127 128 129 |
# File 'lib/puppeteer/bidi/cookie_utils.rb', line 125 def self.(, normalized_url) return false unless (, normalized_url) (, normalized_url) end |
.test_url_match_cookie_hostname(cookie, normalized_url) ⇒ Boolean
134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/puppeteer/bidi/cookie_utils.rb', line 134 def self.(, normalized_url) url_hostname = normalized_url.host return false if url_hostname.nil? = .fetch("domain", "").downcase url_hostname = url_hostname.downcase return true if == url_hostname .start_with?(".") && url_hostname.end_with?() end |
.test_url_match_cookie_path(cookie, normalized_url) ⇒ Boolean
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/puppeteer/bidi/cookie_utils.rb', line 149 def self.(, normalized_url) uri_path = normalized_url.path uri_path = "/" if uri_path.nil? || uri_path.empty? = ["path"] || "/" return true if uri_path == if uri_path.start_with?() return true if .end_with?("/") return true if uri_path[.length] == "/" end false end |