Skip to content

Commit

Permalink
Allow debugging gdcef
Browse files Browse the repository at this point in the history
  • Loading branch information
Lecrapouille committed Jul 23, 2024
1 parent f1c2947 commit a02c79d
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 14 deletions.
5 changes: 4 additions & 1 deletion addons/gdcef/demos/2D/CEF.gd
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ func _ready():
# {"log_file", resource_path / "debug.log"}
# {log_severity", "warning"}
# {"remote_debugging_port", 7777}
# {"remote_allow_origin", "*"}
# {"exception_stack_size", 5}
# {"enable_media_stream", false}
#
Expand All @@ -334,7 +335,9 @@ func _ready():
if !$CEF.initialize({
"incognito":true,
"locale":"en-US",
"enable_media_stream": true
"enable_media_stream": true,
"remote_debugging_port": 7777,
"remote_allow_origin": "*"
}):
$Panel/VBox/HBox2/Info.set_text($CEF.get_error())
push_error($CEF.get_error())
Expand Down
21 changes: 12 additions & 9 deletions addons/gdcef/doc/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,28 @@ Depending for `entry` concerning the `get_version_part`:
Since Godot `_init` does not accept passing arguments, you have to use `initialize` function
instead. You also have to pass a Godot dictionary to configurate
the behavior for CEF. Default values are:
- `{"artifcats":CEF_ARTIFACTS_FOLDER}` Path where the build CEF artifcats are stored. They are
- `{"artifcats": CEF_ARTIFACTS_FOLDER}` Path where the build CEF artifcats are stored. They are
needed to make CEF running and therefore your application. Fort this section, we will give the
name `cef_folder_path` to the result. The default value is given during the compilation with
the build.py script. You can specify either a local path or a global path or a Godot path
(starting with `"res://"`).
- `{"exported_artifcats":application_real_path()}` Path where the build CEF artifcats are stored
- `{"exported_artifcats": application_real_path()}` Path where the build CEF artifcats are stored
when the Godot application is exported. Artifcats are needed to make CEF running and therefore
your application. It defines `cef_folder_path`.
- `{"incognito":false}` : In incognito mode cache directories not used and in-memory caches are
- `{"incognito": false}` : In incognito mode cache directories not used and in-memory caches are
used instead and no data is persisted to disk.
- `{"cache_path":cef_folder_path / "cache"}` : Folder path where to store CEF caches.
- `{"root_cache_path":cef_folder_path / "cache"}`
- `{"browser_subprocess_path":cef_folder_path / SUBPROCESS_NAME }` : canonical path to the CEF
- `{"cache_path": cef_folder_path / "cache"}` : Folder path where to store CEF caches.
- `{"root_cache_path": cef_folder_path / "cache"}`
- `{"browser_subprocess_path": cef_folder_path / SUBPROCESS_NAME }` : canonical path to the CEF
subprocess called during the `initialize()` function. The default name is determined during the
compilation done with the build.py script.
- `{"log_file":cef_folder_path / "debug.log"}` : Where to store logs.
- `{log_severity":"warning"}` : Verbosity control of logs. Choose between `"verbose"`, `"info"`,
- `{"log_file": cef_folder_path / "debug.log"}` : Where to store logs.
- `{"log_severity": "warning"}` : Verbosity control of logs. Choose between `"verbose"`, `"info"`,
`"warning"`, `"error"`, `"fatal"`.
- `{"remote_debugging_port":7777}` : the port for debbuging CEF.
- `{"remote_allow_origin": "*"}` : to allow debug connections from all origins.
- `{"remote_debugging_port":7777}` : the port for debbuging gdcef from a Chrome browser.
From Chrome URL, type: `http://localhost:7777` you will see list of link. Click on one and you will
see your page for debugging. See this [screenshot](pics/debug.png).
- `{"exception_stack_size":5}`
- `{"locale":"en-US"}` : Select your language.
- `{"enable_media_stream", false}` : allow CEF to access to your camera and microphones.
Expand Down
2 changes: 1 addition & 1 deletion addons/gdcef/doc/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ been created to wrap the CEF C++ API to be usable from Godot scripts. Derived
from Godot Nodes, it allows instances of these classes to be attached inside to
the scene-graph as depicted by the following picture.

![CEFnode](scenegraph/cef.png)
![CEFnode](pics/cef.png)

See this
[document](https://docs.godotengine.org/en/stable/classes/class_node.html)
Expand Down
2 changes: 1 addition & 1 deletion addons/gdcef/doc/detailsdesign.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ and the entry function for the module.
To use the native module inside Godot, ensure libraries are correctly loaded
into your project. Then create a `GDCEF` node in the scene graph.

![CEFnode](scenegraph/cef.png)
![CEFnode](pics/cef.png)

**Beware:** In Linux, you will have to write something like:
```
Expand Down
12 changes: 12 additions & 0 deletions addons/gdcef/doc/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,15 @@ information):
```
$CEF.initialize({"artifacts": "res://cef_artifacts/", ... })
```

## Debug gdcef

In your gd script, when init CEF. Pass the following settings:

```
$CEF.initialize({"remote_debugging_port": 7777, "remote_allow_origin": "*", ... })
```

Open a Chrome browser and type in the URL: `http://localhost:7777`. You will see something like this:

![Debug](pics/debug.png)
File renamed without changes
Binary file added addons/gdcef/doc/pics/debug.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 11 additions & 2 deletions addons/gdcef/gdcef/src/gdcef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ bool GDCef::initialize(godot::Dictionary config)
// because we cannot access to it, we have to configure CEF directly.
configureCEF(cef_folder_path, m_cef_settings, m_window_info, config);
m_enable_media_stream = getConfig(config, "enable_media_stream", false);
m_remote_allow_origin = getConfig(config, "remote_allow_origin", std::string{});

// This function should be called on the main application thread to
// initialize the CEF browser process. A return value of true indicates
Expand Down Expand Up @@ -334,8 +335,8 @@ static void configureCEF(fs::path const& folder, CefSettings& cef_settings,
cef_settings.command_line_args_disabled = true;

// Set to a value between 1024 and 65535 to enable remote debugging on the
// specified port. For example, if 8080 is specified the remote debugging
// URL will be http://localhost:8080. CEF can be remotely debugged from any
// specified port. For example, if 7777 is specified the remote debugging
// URL will be http://localhost:7777. CEF can be remotely debugged from any
// CEF or Chrome browser window. Also configurable using the
// "remote-debugging-port" command-line switch.
cef_settings.remote_debugging_port =
Expand Down Expand Up @@ -546,4 +547,12 @@ void GDCef::Impl::OnBeforeCommandLineProcessing(const CefString& ProcessType,
GDCEF_DEBUG_VAL("Allow enable-media-stream");
command_line->AppendSwitch("enable-media-stream");
}

// To be usable with cef_settings.remote_debugging_port.
// Set to "*".
if (!m_owner.m_remote_allow_origin.empty())
{
command_line->AppendSwitchWithValue(
"remote-allow-origins", m_owner.m_remote_allow_origin.c_str());
}
}
2 changes: 2 additions & 0 deletions addons/gdcef/gdcef/src/gdcef.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ class GDCef : public godot::Node
mutable std::stringstream m_error;
//! \brief Allow accessing to camera and microphones
bool m_enable_media_stream = false;
//! \brief To be usable with cef_settings.remote_debugging_port.
std::string m_remote_allow_origin;
};

# if !defined(_WIN32)
Expand Down

0 comments on commit a02c79d

Please sign in to comment.