Reputation: 3
I'm attempting to add a custom command line option to the Chromium source code on windows, allowing me to run the browser with a flag like chrome.exe --my-custom-flag=value
. The goal is to access this value anywhere within the Chromium codebase. However, my attempts so far have been unsuccessful.
I've tried using the following code snippet to read the command line value within the Chromium source:
std::string value = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII("my-custom-flag");
However, this method didn't yield the desired result. I also tried another approach using the CommandLine::ForCurrentProcess()->HasSwitch()
method to check if the custom flag was present, but it didn't work either.
I would greatly appreciate any advice or guidance on how to properly implement and read a custom command line option in the Chromium source code. Thank you in advance for your assistance.
Upvotes: 0
Views: 832
Reputation: 38559
third_party/blink/renderer/core/frame/navigator.cc
is a part of Chromium renderer process, you attempt to run your code in a renderer. You command line switch --my-custom-flag
is not forwarded to a renderer process, it is filtered out in
void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer(
const base::CommandLine& browser_cmd,
base::CommandLine* renderer_cmd);
Add your switch to the array kSwitchNames
in that member function, and it will be propagated to a renderer process. Note, all switches must be defined without the beginning double dashes --
.
Upvotes: 2