Skip to content

Commit d9981c6

Browse files
authored
Merge pull request #24 from gauthamsriman/origin-uptodate
Keep origin up-to-date
2 parents 8bc1c9d + c562604 commit d9981c6

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/consumer/frame.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ class Frame extends EventEmitter {
198198
// 2. Identify the app the message came from.
199199
if (this.iframe.contentWindow !== event.source) return;
200200

201+
// For Chrome, the origin property is in the event.originalEvent object.
202+
// Update origin so it can be used to post back to this frame.
203+
this.origin = event.origin || event.originalEvent.origin;
204+
201205
logger.log('<< consumer', event.origin, event.data);
202206

203207
// 3. Send a response, if any, back to the app.

test/frame.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,17 @@ describe('Frame', () => {
145145
sinon.assert.called(handle);
146146
});
147147

148+
it("updates the app's origin to match the frame's origin", () => {
149+
const event = {
150+
data: {jsonrpc: '2.0'},
151+
source: frame.iframe.contentWindow,
152+
origin: 'http://localhost:8080'
153+
};
154+
frame.handleProviderMessage(event);
155+
156+
expect(frame.origin).to.equal(event.origin);
157+
});
158+
148159
it("calls this.JSONRPC.handle with the data of given event", () => {
149160
const event = {
150161
data: {jsonrpc: '2.0'},

0 commit comments

Comments
 (0)