New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Eliminate space counted as message length #23451
Conversation
When separators=(',', ':') is not passed to json.dumps() parameter the length for input from JavaScript (which is serialized to a JSON-like format by the application) port.postMessage(new Array(174763)); is read in Python as 1048578 which is greater than 1024*1024. Essentially space character formatting were being encoded as part of the length of the JSON. When the length should be 873816 when formatting space characters are excluded from the JSON. Solved by passing separators=(',', ':') for “compact encoding” json — JSON encoder and decoder — Python 3.11.1 documentation. Now we can write 1MB with port.postMessage(new Array(209715)); from JavaScript and omit including and counting formatting space characters as part of encoded message length.
Preview URLs (comment last updated: 2023-01-14 19:31:00) |
# https://docs.python.org/3/library/json.html#basic-usage | ||
# To get the most compact JSON representation, you should specify | ||
# (',', ':') to eliminate whitespace. | ||
encodedContent = json.dumps(messageContent, separators=(',', ':')).encode('utf-8') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
encodedContent = json.dumps(messageContent, separators=(',', ':')).encode('utf-8') | |
encoded_content = json.dumps(message_content, separators=(',', ':')).encode('utf-8') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
I realized they use different casing styles. That sucks a bit. We can wait for @Rob--W to review and merge both PRs. |
Review addressed; waiting for maintainer opinion
We're working that out now mdn/webextensions-examples#510. Not sure what the hesitancy is. The script in its current form is not so clearly, yet still broken. Feel free provide your feedback there too. |
The motivation is convincing and the code is also clear. I don't have enough domain knowledge to review it, but everything LGTM at a glance from an engineering perspective. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address the issue below together with the feedback in mdn/webextensions-examples#510.
files/en-us/mozilla/add-ons/webextensions/native_messaging/index.md
Outdated
Show resolved
Hide resolved
@Rob--W Kindly review the changes made. |
files/en-us/mozilla/add-ons/webextensions/native_messaging/index.md
Outdated
Show resolved
Hide resolved
files/en-us/mozilla/add-ons/webextensions/native_messaging/index.md
Outdated
Show resolved
Hide resolved
files/en-us/mozilla/add-ons/webextensions/native_messaging/index.md
Outdated
Show resolved
Hide resolved
files/en-us/mozilla/add-ons/webextensions/native_messaging/index.md
Outdated
Show resolved
Hide resolved
…ex.md Co-authored-by: Rob Wu <rob@robwu.nl>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of the requested changes from my previous review haven't been made yet.
This comment was marked as abuse.
This comment was marked as abuse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks. For consistency I'd also use /usr/bin/env -S python2 -u
, but that's a pre-existing issue.
Yes, that would be optimal to avoid ambiguity. Why are we even still deploying examples using |
Updated. |
When separators=(',', ':') is not passed to json.dumps() parameter the length for input from JavaScript (which is serialized to a JSON-like format by the application) port.postMessage(new Array(174763)); is read in Python as
1048578
which is greater than 1024*1024. Essentially space character formatting were being encoded as part of the length of the JSON.
When the length should be
873816
when formatting space characters are excluded from the JSON.
Solved by passing separators=(',', ':') for “compact encoding” json — JSON encoder and decoder — Python 3.11.1 documentation.
Now we can write 1MB with
port.postMessage(new Array(209715));
from JavaScript and omit including and counting formatting space characters as part of encoded message length.
Description
Motivation
Additional details
Related issues and pull requests