Git Product home page Git Product logo

postmate's Introduction

A powerful, simple, promise-based postMessage iFrame communication library.

npm CircleCI Share

Postmate is a promise-based API built on postMessage. It allows a parent page to speak with a child iFrame across origins with minimal effort.

You can download the compiled javascript directly here


Features

Greenkeeper badge

  • Promise-based API for elegant and simple communication.
  • Secure two-way parent <-> child handshake, with message validation.
  • Child exposes a retrievable model object that the parent can access.
  • Child emits events that the parent can listen to.
  • Parent can call functions within a child
  • Zero dependencies. Provide your own polyfill or abstraction for the Promise API if needed.
  • Lightweight, weighing in at ~ 1.6kb (minified & gzipped).

NOTE: While the underlying mechanism is window.postMessage(), only iFrame is supported.

Installing

Postmate can be installed via NPM.

NPM

$ yarn add postmate # Install via Yarn
$ npm i postmate --save # Install via NPM

Glossary

  • Parent: The top level page that will embed an iFrame, creating a Child.
  • Child: The bottom level page loaded within the iFrame.
  • Model: The object that the Child exposes to the Parent.
  • Handshake: The process by which the parent frame identifies itself to the child, and vice versa. When a handshake is complete, the two contexts have bound their event listeners and identified one another.

Usage

  1. The Parent begins communication with the Child. A handshake is sent, the Child responds with a handshake reply, finishing Parent/Child initialization. The two are bound and ready to communicate securely.

  2. The Parent fetches values from the Child by property name. The Child can emit messages to the parent. The Parent can call functions in the Child Model.


Example

parent.com

// Kick off the handshake with the iFrame
const handshake = new Postmate({
  container: document.getElementById('some-div'), // Element to inject frame into
  url: 'http://child.com/page.html', // Page to load, must have postmate.js. This will also be the origin used for communication.
  name: 'my-iframe-name', // Set Iframe name attribute. Useful to get `window.name` in the child.
  classListArray: ["myClass"] //Classes to add to the iframe via classList, useful for styling.
});

// When parent <-> child handshake is complete, data may be requested from the child
handshake.then(child => {

  // Fetch the height property in child.html and set it to the iFrames height
  child.get('height')
    .then(height => child.frame.style.height = `${height}px`);

  // Listen to a particular event from the child
  child.on('some-event', data => console.log(data)); // Logs "Hello, World!"
});

child.com/page.html

const handshake = new Postmate.Model({
  // Expose your model to the Parent. Property values may be functions, promises, or regular values
  height: () => document.height || document.body.offsetHeight
});

// When parent <-> child handshake is complete, events may be emitted to the parent
handshake.then(parent => {
  parent.emit('some-event', 'Hello, World!');
});

API

Postmate.debug

// parent.com or child.com
Postmate.debug = true;
new Postmate(options);
Name Type Description Default
debug Boolean Set to true to enable logging of additional information false

Postmate.Promise

// parent.com or child.com
Postmate.Promise = RSVP.Promise;
new Postmate(options);
Name Type Description Default
Promise Object Replace the Promise API that Postmate uses window.Promise

Postmate(options)

// parent.com
new Postmate({
  container: document.body,
  url: 'http://child.com/',
  classListArray: ["myClass"]
  model: { foo: 'bar' }
});

This is written in the parent page. Creates an iFrame at the specified url. Initiates a connection with the child. Returns a Promise that signals when the handshake is complete and communication is ready to begin.

Returns: Promise(child)

Properties

Name Type Description Default
container (optional) DOM Node Element An element to append the iFrame to document.body
url String A URL to load in the iFrame. The origin of this URL will also be used for securing message transport none
classListArray Array An Array to add classes to the iFrame. Useful for styling none
model Object An object literal to represent the default values of the Childs model none

Postmate.Model(model)

// child.com
new Postmate.Model({
  // Serializable values
  foo: "bar",
  // Functions
  height: () => document.height || document.body.offsetHeight,
  // Promises
  data: fetch(new Request('data.json'))
});

This is written in the child page. Calling Postmate.Model initiates a handshake request listener from the Child. Once the handshake is complete, an event listener is bound to receive requests from the Parent. The Child model is extended from the model provided by the Parent.

Returns: Promise(handshakeMeta)

Parameters

Name Type Description Default
model Object An object of gettable properties to expose to the parent. Value types may be anything accepted in postMessage. Promises may also be set as values or returned from functions. {}

child.get(key)

// parent.com
new Postmate({
  container: document.body,
  url: 'http://child.com/'
}).then(child => {
  child.get('something').then(value => console.log(value));
});

Retrieves a value by property name from the Childs model object.

Returns: Promise(value)

Parameters

Name Type Description
key String (required) The string property to lookup in the childs model

child.call(key, data)

// parent.com
new Postmate({
  container: document.body,
  url: 'http://child.com/'
}).then(child => {
  child.call('sayHi', 'Hello, World!');
});

Calls the function sayHi in the Child Model with the parameter Hello, World!

Returns: undefined

Parameters

Name Type Description
key String (required) The string property to lookup in the childs model
data Mixed The optional data to send to the child function

child.destroy()

// parent.com
new Postmate({
  container: document.body,
  url: 'http://child.com/'
}).then(child => child.destroy());

Removes the iFrame element and destroys any message event listeners

Returns: undefined


child.frame

new Postmate(options).then(child => {
  child.get('height')
    .then(height => child.frame.style.height = `${height}px`);
});

The iFrame Element that the parent is communicating with

Troubleshooting/FAQ

General

Why use Promises for an evented API?

Promises provide a clear API for fetching data. Using an evented approach often starts backwards. if the parent wants to know the childs height, the child would need to alert the parent, whereas with Postmate, the Parent will request that information from the child in a synchronous-like manner. The child can emit events to the parent as well, for those other use-cases that still need to be handled.

Silent Parent/Child

I've enabled logging but the parent or child is not logging everything.

Postmate.debug needs to be set in both the parent and child for each of them to log their respective information

The child does not respond to communication from the Parent

Make sure that you have initialized Postmate.Model in your child page.

Restrictive Communication

I want to retrieve information from the parent by the child

Postmate (by design) is restrictive in its modes of communication. This enforces a simplistic approach: The parent is responsible for logic contained within the parent, and the child is responsible for logic contained within the child. If you need to retrieve information from parent -> child, consider setting a default model in the parent that the child may extend.

I want to send messages to the child from the parent

This is specifically what the call function is for.

Security

What is the Handshake and why do I need one?

By default, all message events received by any (parent) page can come from any (child) location. This means that the Parent must always enforce security within its message event, ensuring that the child (origin) is who we expect them to be, that the message is a response from an original request, and that our message is valid. The handshake routine solves this by saving the identities of the child and parent and ensuring that no changes are made to either.

How are messages validated?

The origin of the request, the message type, the postMessage mime-type, and in some cases the message response, are all verified against the original data made when the handshake was completed.

License

MIT

postmate's People

Contributors

44px avatar amilajack avatar andarist avatar betocantu93 avatar briangonzalez avatar dboskovic avatar greenkeeper[bot] avatar hemkaran avatar ivalsaraj avatar jakiestfu avatar jonathanong avatar karamosky avatar knightus avatar kylecorbelli avatar lianer avatar lots0logs avatar renovate[bot] avatar rooseveltlai avatar sletheren avatar teramotodaiki avatar yowainwright avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

postmate's Issues

Change the frame URL

Hi
Is it possible to change the frame url ? and if it is, how is the handling of the onload

SupportsMessageChannel breaks child iframe

In an app I'm working on, upgrading from v.1.4.2 to v1.4.5 gives the following error in child iframes:

Uncaught (in promise) DOMException: Failed to execute 'postMessage' on 'Window': Invalid target origin 'undefined' in a call to 'postMessage'.

The error originates from src/postmate.js#L88

An in-range update of @babel/core is breaking the build 🚨

Version 7.0.0-beta.51 of @babel/core was just published.

Branch Build failing 🚨
Dependency @babel/core
Current Version 7.0.0-beta.50
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

@babel/core is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Supported browsers/versions ?

Hi,

I didn't find on your documentation what are the browsers (and minimum version) supported. Is this described somehwere?

IE10 - method 'on' not invoked before Parent: Received event emission

Before test in IE, merge #43
When parent <-> child handshake is complete, and child emit a event immediately, like:
handshake.then(parent => { parent.emit('some-event', 'Hello, World!'); });

in IE10, the if condition is false, so the event is not fired.
if (name in this.events) { this.events[name].call(this, data) }

Delay child's emit can fix this temporary
handshake.then(parent => { setTimeout(() => parent.emit('some-event', 'Hello, World!'), 2000); });

But how to fix this really?

An in-range update of uglify-js is breaking the build 🚨

Version 3.4.6 of uglify-js was just published.

Branch Build failing 🚨
Dependency uglify-js
Current Version 3.4.5
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

uglify-js is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: Your tests failed on CircleCI (Details).

Release Notes v3.4.6

 

Commits

The new version differs by 5 commits.

  • 2a5277b v3.4.6
  • d47547d fix corner case in join_vars (#3224)
  • 304db15 fix corner case in ie8 & rename (#3223)
  • 7cf72b8 fix corner case in global_defs (#3218)
  • cea685f fix corner case in ie8 (#3216)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of regenerator-runtime is breaking the build 🚨

Version 0.12.1 of regenerator-runtime was just published.

Branch Build failing 🚨
Dependency regenerator-runtime
Current Version 0.12.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

regenerator-runtime is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: Your tests failed on CircleCI (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of rollup is breaking the build 🚨

Version 0.63.5 of rollup was just published.

Branch Build failing 🚨
Dependency rollup
Current Version 0.63.4
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

rollup is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: Your tests failed on CircleCI (Details).

Commits

The new version differs by 11 commits.

  • dc9f347 0.63.5
  • 6c1d1e6 Fix typings for turbo color
  • e109576 Update changelog
  • 115239f Update changelog
  • da97ea5 Add plugin implemenation type (#2355)
  • 55d90d8 fix regression #2305, ensure onwrite plugin hooks execute in sequence (#2364)
  • fc1e6f7 Update changelog
  • d07d5bf Always warn when no name is provided for a global module (#2359)
  • 489477d Update changelog
  • 9eaa1d9 Remove "es6" output format from types (#2349)
  • 382323a fix(types): inlineDynamicImports is optional (#2348)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Question about child.call and returned value

Is there some limitations/caveats for child.call returned value as promise, like it's done at child.get functionality? Because if I need to pass some arguments to child model functions, then I need to switch from promise based code to event driven style.. but I wanna use just one of it

Cannot resolve multiple promises at once

Attempting to resolve multiple promises at once causes an issue where subsequent promises are resolved with the initial promises value.

var promises = {
  foo: child.get("foo"),
  bar: child.get("bar"),
};

RSVP.hash(promises).then(function(results) {
  console.log(results.foo) // prints "foo"
  console.log(results.bar) // prints "foo"
});

Review postMessage helper method

What Is the issue?

With the initial reversion of potentially temporary MessageChannel usage, implementing the postMessage helper method from here appears to be a solid addition

Provide issue context below using code examples, images, or links

After publishing and confirming a successful publish (hopefully 1.4.8), the postMessage method will be added along with more tests.


Read about references issues here. Provide paragraph text responses to each header.

An in-range update of rollup is breaking the build 🚨

The devDependency rollup was updated from 1.0.0 to 1.0.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

rollup is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: Your tests failed on CircleCI (Details).

Release Notes for v1.0.1

2019-01-03

Bug Fixes

  • Properly handle reexporting an external default export for non-ESM targets when using named exports mode (#2620)
  • Do not (wrongly) re-declare input options in the merged RollupOptions type (#2622)

Pull Requests

Commits

The new version differs by 6 commits.

  • fbb5f9e 1.0.1
  • e7b3c78 Update changelog
  • eda15fa Update changelog
  • 5ff6352 Show how to skip imports for optional plugins (#2627)
  • 6d32530 Simplify RollupOptions (#2622)
  • f5364d9 Fixed issue with reexporting default as default with {exports: named, interop: true} options. (#2620)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Question: Attach postmate to existing iframe instead of having postmate create one

Thanks for putting together this useful component. I'm new to using postMessage for communication and appreciate that I could find something which handles some of the complexities and security of dealing with iframes.

I'd like to use this library as part of a project I'm working on, and was wondering if I have an existing iframe rendered, can I attached postmate to that iframe instead? The reason for that is that I'm using react and preference would be to have react deal with the DOM manipulations.

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml
  • Replaced the old Node.js version in your .nvmrc with the new one

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

[discussion] MessageChannels

Have you considered using MessageChannels instead of bare postMessage? It potentially could allow for more secure communication between parent & the child

An in-range update of es-check is breaking the build 🚨

Version 2.1.0 of es-check was just published.

Branch Build failing 🚨
Dependency es-check
Current Version 2.0.4
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

es-check is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: Your tests failed on CircleCI (Details).

Commits

The new version differs by 8 commits.

  • 338e131 [update] code style: tweaks + docs (#53)
  • 7c978ad [version] feature version bump => .escheckrc (@MrBenJ) 😍 (#52)
  • 5ac8450 Added option to use an .escheckrc file for config (#51)
  • b76a891 [SECURITY]: resolution of eslint-scope to 3.7.1 (#50)
  • e8eb599 chore(package): update eslint to version 5.0.0 (#48)
  • 3826159 fix(package): update acorn to version 5.7.0 (#47)
  • 754ffd1 chore(package): update nyc to version 12.0.1 (#46)
  • 90d1ae7 fix(package): update acorn to version 5.6.0 (#45)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Possible Bug In sendHandshakeReply()

This condition will always be true even when there are no ports in the array:

postmate/src/postmate.js

Lines 440 to 445 in e57a719

if (ports) {
const port = ports[0]
port.postMessage(reply)
this.source = port
port.start()
} else {

I stumbled upon this because the latest release doesn't work when an iframe is the parent window of a child iframe. The code on master appears to work in my testing thus far (apart from the above issue).

Uncaught (in promise) Handshake Reply Failed

thougth there is the same issue, but my question is not same to it.
i can normally use it, but when my project initial, it will cause "Uncaught (in promise) Handshake Reply Failed", then it runs normally

Drop logs in production builds

Would you accept PR removing logs in production builds? I would simply wrap all logs with (if (process.env.NODE !== 'production')). This would save us 294 bytes, I suspect you do need those debugs only in dev mode.

Is it working with window.open ?

Hi !

Your lib seems to be really cool but I want to know if it work with a window.open created window or if it just work with iframes ?

Thanks :)

An in-range update of rollup-plugin-babel is breaking the build 🚨

The devDependency rollup-plugin-babel was updated from 4.3.0 to 4.3.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

rollup-plugin-babel is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: Your tests failed on CircleCI (Details).

Commits

The new version differs by 4 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

why is parent -> child communication bad

The parent cannot send messages. However, a simple request to a function in the child via child.get is possible, and can solve most scenarios, but is advised against.

Why?

npm run build

$ npm run build

> [email protected] build /Users/jong/code/postmate
> gulp build && gulp update-readme

[14:30:50] Using gulpfile ~/code/postmate/gulpfile.js
[14:30:50] Starting 'do-build'...
[14:30:50] Starting 'update-readme'...
[14:30:50] Finished 'update-readme' after 639 μs
resolve failed:  { Error: Cannot find module 'babel-runtime'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.requireRelative.resolve (/Users/jong/code/postmate/node_modules/require-relative/index.js:30:17)
    at resolve (/Users/jong/code/postmate/node_modules/modify-babel-preset/lib/serialize.js:25:26)
    at findAndRemove (/Users/jong/code/postmate/node_modules/modify-babel-preset/lib/serialize.js:67:11)
    at /Users/jong/code/postmate/node_modules/modify-babel-preset/lib/serialize.js:111:13
    at Array.map (native)
    at loadPreset (/Users/jong/code/postmate/node_modules/modify-babel-preset/lib/serialize.js:103:29)
    at module.exports (/Users/jong/code/postmate/node_modules/modify-babel-preset/index.js:97:19)
    at Object.<anonymous> (/Users/jong/code/postmate/node_modules/babel-preset-es2015-rollup/index.js:3:18)
    at Module._compile (module.js:571:32) code: 'MODULE_NOT_FOUND' } babel-runtime
phantomjs terminated with signal SIGSEGV

Reconnection - feature -

What Is the issue?

There are some use cases when child iframes reload, it would be cool if we can automatically get an auto handshake or something like that to reconnect the child to the parent... in my particular case, whenever a user logouts I reload the iframe, but currently with postmate the connection is lost (?), unless you make a super hacky work around.

Provide issue context below using code examples, images, or links


Penpal uses this approach
https://github.com/Aaronius/penpal#reconnection

Read about references issues here. Provide paragraph text responses to each header.

An in-range update of @babel/plugin-proposal-class-properties is breaking the build 🚨

Version 7.0.0-beta.51 of @babel/plugin-proposal-class-properties was just published.

Branch Build failing 🚨
Dependency @babel/plugin-proposal-class-properties
Current Version 7.0.0-beta.50
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

@babel/plugin-proposal-class-properties is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Release new version

Hi! I just wanted to ask if you have any release date for the new version? 1.4.0 is a little bit stale in comparison to master.

Child Frame Navigation in version 1.4.7

In the case where a child frame navigates to a new page (user clicks a link in the frame), it seems like a connection between a parent and the new child is not maintained.

I've enabled logging, and the parent logs "Parent: Received handshake reply from Child" after the navigation, but no events are being sent.

However, in version 1.4.1, the connection seems to be maintained, and messages are sent.

Any ideas? I can try to reproduce this minimally, if that would help.

Thanks.

it will be blocked when page is across origin.

the code at line 218 is not work when the source is across origin:

    // when parent page is across origin, the browser will block this.
    this.source.addEventListener('message', (e) => {
      if (!sanitize(e, this.parentOrigin)) return

      if (process.env.NODE_ENV !== 'production') {
        log('Child: Received request', e.data)
      }

so, whether we should judge the parent's origin before bind the enent listener ?

An in-range update of conventional-changelog-cli is breaking the build 🚨

The devDependency conventional-changelog-cli was updated from 2.0.5 to 2.0.7.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

conventional-changelog-cli is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: Your tests failed on CircleCI (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Ember example

Hi there. This library looks awesome. Could you give an example of how one would import it into an Ember app?

ie11 childOrigin get wrong url cause postmessage fail

i debug the source code,the function resolveOrigin try to get target origin by the line:
a.origin || a.protocol + '//' + a.hostname
but in my ie 11,origin is undefined,and protocol and hostname is empty string
00

Support multiple instances on a page

I'm writing an application where a parent would initiate connections with several children on the same page:

new Postmate({ ... }).then(child1 => {
  child1.on('some-event', data => console.log("Message from Child 1", data));
});

new Postmate({ ... }).then(child2 => {
  child2.on('some-event', data => console.log("Message from Child 2", data));
});

The problem is that if either child sends the event some-event, then we get the callbacks called twice:

Message from Child 1 Hello World
Message from Child 2 Hello World

I believe this is the problem:

this.parent.addEventListener('message', this.listener, false); // 'message' listener will receive all messages from all children

Previously I used EasyXDM for cross domain communication. They solve this problem by having a unique ID associated with every handshake/connection.

Would you consider adding support for this?

[feature request] multiple callbacks for an event

At the moment it's only possible to setup a single callback for a given event type -

this.events[eventName] = callback

I think it's really convenient to hook into a single event from multiple places (therefore with multiple callbacks). Also it would be cool to have corresponding off method, but that's a separate issue.

If you think that would be a nice addition to the library I can add it quickly, I would just use extremely small mitt (<200 B) as underlaying emitter.

An in-range update of eslint-config-dollarshaveclub is breaking the build 🚨

The devDependency eslint-config-dollarshaveclub was updated from 3.1.0 to 3.1.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint-config-dollarshaveclub is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: Your tests failed on CircleCI (Details).

Commits

The new version differs by 10 commits.

  • 2269cb3 [version] patch version bump; pkg updates; node update (#48)
  • 56688db Update eslint-plugin-ember to the latest version 🚀 (#47)
  • f33118a Update eslint-config-standard-react to the latest version 🚀 (#43)
  • 0de217e fix(package): update eslint-config-standard to version 12.0.0 (#45)
  • 6a9e088 fix(package): update eslint-plugin-standard to version 4.0.0 (#44)
  • ff7cc92 fix(package): update babel-eslint to version 9.0.0 (#42)
  • 6175554 Update eslint-plugin-node to the latest version 🚀 (#46)
  • c507de7 fix(package): update eslint-plugin-node to version 7.0.0 (#40)
  • c36c230 fix(package): update eslint-plugin-promise to version 4.0.0 (#41)
  • de62235 fix(package): update eslint to version 5.0.0 (#39)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Uncaught (in promise) Handshake Reply Failed

i use in vue

import Postmate from 'postmate';
Postmate.debug = true;
export default {
data () {
return {
parentWrap: null,
handshake: null,
};
},
mounted () {
this.handshake = new Postmate.Model({
content: () => 'it’s child!',
});
},
created () {
},
methods: {
handlePost() {
//it can't work
this.handshake.then((parent) => {
parent.emit('some-event', 'child emit');
});
},
},
};

Child fails to complete handshake

What Is the issue?

Getting this in the console, following your basic example:

Uncaught DOMException: Failed to execute 'postMessage' on 'Window': Invalid target origin 'null' in a call to 'postMessage'.

Provide issue context below using code examples, images, or links

screen shot 2018-11-19 at 09 15 53


Parent instantiation:

import Postmate from "postmate"
Postmate.debug = true

const handshake = new Postmate({
    container: document.getElementById('virtual-adviser-initial-container'),
    url: 'https://virtual-adviser.test/cross-origin-enquiry/', 
    classListArray: ["mw-full"]
});


handshake.then(child => {
    child.get('height')
      .then(height => child.frame.style.height = `${height}px`);
    child.on('some-event', data => console.log(data)); // Logs "Hello, World!"
});

Tried using v1.4.2 and ^v1.4.8 with the same issue. Can you shed any light as to why this would be happening? Many thanks 👍🏼

An in-range update of @babel/preset-env is breaking the build 🚨

Version 7.0.0-beta.51 of @babel/preset-env was just published.

Branch Build failing 🚨
Dependency @babel/preset-env
Current Version 7.0.0-beta.50
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

@babel/preset-env is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

How does postmate ensure that messages are only coming from authorized origins?

Hey @jakiestfu

Great work as usual :)

I was curious about how postmate ensures that all messages are coming from authorized origins to avoid xss attacks.

I saw sanitize, which appears to be checking parentOrigin in the ChildAPI constructor, but I was unable to see where each parentOrigin is validated on a per message basis.

Give the guys my best, and keep up the good work.

EDIT: NVM I just realized that it was declaring an event handler in the ChildAPI constructor.

Exception created when there are other iframe running playerjs

What Is the issue?

I'm developing an extension running on linkedin.com, which will create a small iframe in some use cases. In LinkedIn feed page, if there's a running video, postmate will create the exceptions.

Debugging showing that in thesse cases, the message.data is a string instead of object, which prevented postmate from using in operator

Provide issue context below using code examples, images, or links

Exception

Uncaught TypeError: Cannot use 'in' operator to search for 'postmate' in {"context":"player.js","version":"0.0.12","event":"ready","value":{"src":"https://www.linkedin.com/learning/embed/ux-foundations-style-guides-and-design-systems/setting-the-bar-with-style-guides-and-design-systems?claim=08B2jtaReCXRzyQ%2B8BophcV8rKyxxQRP7qao1FDX5Pg%3D&variant=feed","events":["pause","play","seeked","timeupdate","ended","error","volumechange","mute","unmute","enterfullscreen","exitfullscreen","init","bufferstart","bufferend","bitrateChanged","sharemodalopen","sharemodalclose","shareexternal","ready","progress","endcard_click_view_course"],"methods":["play","pause","getPaused","mute","unmute","getMuted","setVolume","getVolume","getDuration","setCurrentTime","getCurrentTime","setLoop","getLoop","removeEventListener","addEventListener"]}}
    at sanitize (postmate.es.js:75)
    at reply (postmate.es.js:317)

Screenshot:
image

An in-range update of uglify-js is breaking the build 🚨

Version 3.4.1 of uglify-js was just published.

Branch Build failing 🚨
Dependency [uglify-js](https://github.com/mishoo/UglifyJS2)
Current Version 3.4.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

uglify-js is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci Your tests failed on CircleCI Details
  • continuous-integration/travis-ci/push The Travis CI build passed Details

Release Notes v3.4.1

 

Commits

The new version differs by 3 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.