I have implemented code to utilize browser_host->execute_dev_tools_method using the id of the frame passed into cef_load_handler->on_load_error for the frameId parameter.
However my cef_dev_tools_message_observer->on_dev_tools_message method is being called with the following message:
- Code: Select all
{"id":4,"error":{"code":-32000,"message":"No frame for given id found"}}
Why would the frame in on_load_error be giving me an id that is not found when used to setDocumentContent? Is the frame Id expected to be formatted differently? 38654705668
Example of the data being used to construct the method and parameters
- Code: Select all
Method: "Page.setDocumentContent"
Parameters:
"frameId" "38654705668"
"html" "<html><body><h1>Oops, something went wrong...</h1></body></html>"
Function for setting the document content:
- Code: Select all
int set_document_for_frame(cef_frame_t* frame, const char* html_content) {
if (!frame || !html_content)
return -1;
/* Retrieve the browser host from the frame's browser */
cef_browser_t* browser = frame->get_browser(frame);
if (!browser)
return -1;
cef_browser_host_t* browser_host = browser->get_host(browser);
if (!browser_host)
return -1;
guac_http_cef_dev_tools_message_observer_t* observer = guac_http_cef_dev_tools_message_observer();
browser_host->add_dev_tools_message_observer(browser_host,
(cef_dev_tools_message_observer_t*)observer);
/* Construct the DevTools method name */
cef_string_t method= {};
cef_string_from_utf8("Page.setDocumentContent", 23, &method);
/* Create the object for holding the DevTools method parameters */
cef_dictionary_value_t* params = cef_dictionary_value_create();
/* Retrieve the frame's ID as an int64_t */
int64_t frame_id = frame->get_identifier(frame);
/* Create the frameId parameter */
cef_string_t frame_id_key = {};
cef_string_from_utf8("frameId", 7, &frame_id_key);
char frame_id_str[sizeof(int64_t)*8+1];
sprintf(frame_id_str, "%lu", frame_id);
cef_string_t frame_id_str_cef = {};
cef_string_from_utf8(frame_id_str, strlen(frame_id_str), &frame_id_str_cef);
/* Set the frameId in the parameters dictionary */
params->set_string(params, &frame_id_key, &frame_id_str_cef);
/* Create the html parameter */
cef_string_t html_key = {};
cef_string_from_utf8("html", 4, &html_key);
cef_string_t html_content_str = {};
cef_string_from_utf8(html_content, strlen(html_content), &html_content_str);
/* Set the html in the parameters dictionary */
params->set_string(params, &html_key, &html_content_str);
/* Execute the DevTools method */
int message_id = browser_host->execute_dev_tools_method(
browser_host, 0, &method, params);
/* Release resources */
cef_string_clear(&method);
cef_string_clear(&frame_id_key);
cef_string_clear(&frame_id_str_cef);
cef_string_clear(&html_key);
cef_string_clear(&html_content_str);
/* If message_id is 0, the command was not successful */
return (message_id == 0) ? -1 : 0;
}