{"record":{"id":"dc8f94fcd5bb7743","repo":"SeleniumHQ/selenium","slug":"name-is-required","errorCode":null,"errorMessage":"name is required","messagePattern":"name is required","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/common/manager.rb","lineNumber":46,"sourceCode":"        @bridge = bridge\n      end\n\n      #\n      # Add a cookie to the browser\n      #\n      # @param [Hash] opts the options to create a cookie with.\n      # @option opts [String] :name A name\n      # @option opts [String] :value A value\n      # @option opts [String] :path ('/') A path\n      # @option opts [String] :secure (false) A boolean\n      # @option opts [String] :same_site (Strict or Lax) currently supported only in chrome 80+ versions\n      # @option opts [Time,DateTime,Numeric,nil] :expires (nil) Expiry date, either as a Time, DateTime, or seconds since epoch.\n      #\n      # @raise [ArgumentError] if :name or :value is not specified\n      #\n\n      def add_cookie(opts = {})\n        raise ArgumentError, 'name is required' unless opts[:name]\n        raise ArgumentError, 'value is required' unless opts[:value]\n\n        # NOTE: This is required because of https://bugs.chromium.org/p/chromedriver/issues/detail?id=3732\n        opts[:secure] ||= false\n\n        same_site = opts.delete(:same_site)\n        opts[:sameSite] = same_site if same_site\n\n        http_only = opts.delete(:http_only)\n        opts[:httpOnly] = http_only if http_only\n\n        obj = opts.delete(:expires)\n        opts[:expiry] = seconds_from(obj).to_int if obj\n\n        @bridge.add_cookie opts\n      end\n\n      #","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/common/manager.rb#L28-L64","documentation":"Manager#add_cookie requires a :name key in the options hash; a cookie without a name is invalid per the WebDriver specification. The method raises ArgumentError immediately if opts[:name] is missing or nil. A :value is also required (checked next).","triggerScenarios":"Calling driver.manage.add_cookie(value: 'x') with no :name. Passing positional arguments like add_cookie('name', 'value') instead of a hash. Using string keys 'name' that do not match the expected Symbol :name in some code paths.","commonSituations":"Forgetting the hash key and passing values positionally. Building the cookie hash dynamically and the name key is nil/absent. Using a string key where the lookup uses opts[:name] (Symbol).","solutions":["Pass a Hash with both Symbol keys: driver.manage.add_cookie(name: 'sid', value: 'abc').","If building the hash dynamically, ensure the :name key is present and non-nil before calling add_cookie.","Use Symbol keys (:name, :value) rather than string keys to match the documented option names."],"exampleFix":"# before\ndriver.manage.add_cookie(value: 'abc')\n\n# after\ndriver.manage.add_cookie(name: 'sid', value: 'abc')","handlingStrategy":"validation","validationCode":"raise ArgumentError, 'cookie :name is required' unless cookie_hash.key?(:name) && cookie_hash[:name]","typeGuard":"def valid_cookie?(hash)\n  hash.is_a?(Hash) && !hash[:name].nil? && !hash[:value].nil?\nend","tryCatchPattern":"begin\n  driver.manage.add_cookie(opts)\nrescue ArgumentError => e\n  raise unless e.message.include?('name is required')\n  opts = opts.merge(name: default_name)\n  driver.manage.add_cookie(opts)\nend","preventionTips":["Always pass a Hash with Symbol :name and :value keys.","Validate dynamically-built cookie hashes before calling add_cookie.","Avoid positional arguments; add_cookie takes a single options hash."],"tags":["ruby","cookies","validation"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}