Skip to content

Commit 138e87c

Browse files
committed
[scramjet] rewriter: fix optional postMessage access outputting invalid syntax
1 parent b0b1f6a commit 138e87c

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

packages/chrome/src/IsolatedFrame.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,6 @@ const methods = {
487487

488488
const fetchresponse = await controller.fetchHandler.handleFetch(data);
489489

490-
console.log(fetchresponse.headers);
491490
if (
492491
isDownload(fetchresponse.headers, data.destination) &&
493492
fetchresponse.status === 200

packages/rewriter_demo/src/main.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ setConfig({
4141
scramitize: false,
4242
sourcemaps: true,
4343
destructureRewrites: true,
44-
interceptDownloads: false,
4544
allowInvalidJs: false,
4645
allowFailedIntercepts: false,
4746
antiAntiDebugger: false,

packages/scramjet/packages/core/rewriter/js/src/visitor.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,12 @@ where
470470
// however this code only exists because of recaptcha whatever
471471
// and it would slow down js execution a lot
472472
if s.property.name == "postMessage" {
473+
// include the "postMessage" and the dot before it in the inner span
474+
// if `postMessage?.` remove the dot and the question mark
475+
let offset = if s.optional { 1 } else { 2 };
476+
473477
self.jschanges.add(rewrite!(s.span, WrapPostMessage {
474-
// include the "postMessage" and the dot before it (-1)
475-
inner: Span::new(s.property.span.start - 1, s.property.span.end),
478+
inner: Span::new(s.property.span.start - offset, s.property.span.end),
476479
}));
477480

478481
// walk::walk_expression(self, &s.object);

0 commit comments

Comments
 (0)