Skip to content

Commit

Permalink
Add limit to HTTP service's page size
Browse files Browse the repository at this point in the history
Fixes #50
  • Loading branch information
tombh committed Jun 23, 2018
1 parent 61626b5 commit 9ce338f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
13 changes: 13 additions & 0 deletions webext/src/dom/dimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export default class extends utils.mixins(CommonMixin) {
// sent to the TTY to be buffered to support faster scrolling.
this._big_sub_frame_factor = 6;

// The max size in pixels for either the width or height to be for Browsh to parse in
// raw text mode.
// TODO: Use incremental parses to overcome this limit.
this._entire_dom_limit = 30000;

this.dom = {};
this.tty = {};
this.frame = {
Expand Down Expand Up @@ -100,6 +105,14 @@ export default class extends utils.mixins(CommonMixin) {
width: this.dom.width,
height: this.dom.height,
}
if (this.dom.sub.width > this._entire_dom_limit) {
this.dom.sub.width = this._entire_dom_limit;
this.is_page_truncated = true;
}
if (this.dom.sub.height > this._entire_dom_limit) {
this.dom.sub.height = this._entire_dom_limit;
this.is_page_truncated = true;
}
this.frame.sub = {
left: 0,
top: 0,
Expand Down
9 changes: 7 additions & 2 deletions webext/src/dom/serialise_mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export default (MixinBase) => class extends MixinBase {
}

_serialiseRawText() {
let raw_text = "";
let info = '';
let raw_text = '';
this._previous_cell_href = '';
this._is_inside_anchor = false;
const top = this.dimensions.frame.sub.top / 2;
Expand All @@ -41,7 +42,11 @@ export default (MixinBase) => class extends MixinBase {
raw_text += "\n";
}
const head = `<html><title>${document.title}</title><body><pre>`
const foot = `</body></pre></html>`
info += "\n\n" + 'Built by <a href="https://www.brow.sh">Browsh</a>'
if (this.dimensions.is_page_truncated) {
info += '\nBrowsh parser: the page was too large, some text may have been truncated.';
}
const foot = `${info}</pre></body></html>`
return head + raw_text + foot;
}

Expand Down

0 comments on commit 9ce338f

Please sign in to comment.