Skip to content

🐛 Clone IntersectionObserverEntry for cross-origin postMessages#29771

Merged
jridgewell merged 1 commit intoampproject:masterfrom
jridgewell:fix-cross-origin-inob
Aug 10, 2020
Merged

🐛 Clone IntersectionObserverEntry for cross-origin postMessages#29771
jridgewell merged 1 commit intoampproject:masterfrom
jridgewell:fix-cross-origin-inob

Conversation

@jridgewell
Copy link
Copy Markdown
Contributor

@jridgewell jridgewell commented Aug 10, 2020

The target property points to a DOM element, which is not structured clonable (a requirement for postMessage). We used to delete entry.target, to get around this.

But when using native IntersectionObserver, the IntersectionObserverEntrys has no own properties. Instead, the properties are getters that exist on the prototype. delete doesn't work for prototype-inherited properties, so this workaround stopped working. Now, we'll just create a new object with the properties we care about, which is honestly cleaner (you shouldn't mutate objects you don't own).

Fixes #29747

@google-cla google-cla bot added the cla: yes label Aug 10, 2020
@jridgewell jridgewell changed the title Clone IntersectionObserverEntry for cross-origin postMessages 🐛 Clone IntersectionObserverEntry for cross-origin postMessages Aug 10, 2020
@jridgewell jridgewell requested a review from calebcordry August 10, 2020 21:30
@jridgewell
Copy link
Copy Markdown
Contributor Author

/to @calebcordry

The `target` property points to a DOM element, which is not structured clonable (a requirement for `postMessage`). We used to `delete entry.target`, to get around this.

But when using native `IntersectionObserver`, the `IntersectionObserverEntry`s has no own properties. Instead, the properties are getters that exist on the prototype. `delete` doesn't work for prototype-inherited properties, so this workaround stopped working. Now, we'll just create a new object with the properties we care about, which is honestly cleaner (you shouldn't mutate objects you don't own).

Fixes ampproject#29747
@jridgewell jridgewell force-pushed the fix-cross-origin-inob branch from 813c078 to b4b7a60 Compare August 10, 2020 21:44
@jridgewell jridgewell merged commit 85440b5 into ampproject:master Aug 10, 2020
@jridgewell jridgewell deleted the fix-cross-origin-inob branch August 10, 2020 22:24
calebcordry pushed a commit that referenced this pull request Aug 11, 2020
The `target` property points to a DOM element, which is not structured clonable (a requirement for `postMessage`). We used to `delete entry.target`, to get around this.

But when using native `IntersectionObserver`, the `IntersectionObserverEntry`s has no own properties. Instead, the properties are getters that exist on the prototype. `delete` doesn't work for prototype-inherited properties, so this workaround stopped working. Now, we'll just create a new object with the properties we care about, which is honestly cleaner (you shouldn't mutate objects you don't own).

Fixes #29747

(cherry picked from commit 85440b5)
ed-bird pushed a commit to ed-bird/amphtml that referenced this pull request Dec 10, 2020
…ject#29771)

The `target` property points to a DOM element, which is not structured clonable (a requirement for `postMessage`). We used to `delete entry.target`, to get around this.

But when using native `IntersectionObserver`, the `IntersectionObserverEntry`s has no own properties. Instead, the properties are getters that exist on the prototype. `delete` doesn't work for prototype-inherited properties, so this workaround stopped working. Now, we'll just create a new object with the properties we care about, which is honestly cleaner (you shouldn't mutate objects you don't own).

Fixes ampproject#29747
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🚨 Error: Failed to execute 'postMessage' on 'Window': IntersectionObserverEntry object could not be cloned.

4 participants