Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ export default class Client {
this._source = options.source || (this._parent && this._parent._source) || window.parent
this._appGuid = options.appGuid || (this._parent && this._parent._appGuid)
this._instanceGuid = options.instanceGuid || this._appGuid
this._allowOrigin = options.allowOrigin || false
this._messageHandlers = {}
this._repliesPending = {}
this._instanceClients = {}
Expand All @@ -335,7 +336,7 @@ export default class Client {
this._idleState = null
this.ready = false

if (!isOriginValid(this._origin)) {
if (!this._allowOrigin && !isOriginValid(this._origin)) {
const originHostname = new URL(this._origin).hostname
this.postMessage('__track__', {
event_name: 'invalid_sdk_origin',
Expand Down
6 changes: 4 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ import { queryParameters } from './utils'
*/

const ZAFClient = {
init: function (callback, loc) {
init: function (callback, loc, options) {
loc = loc || window.location
options = options || {}
const allowOrigin = options.allowOrigin
const queryParams = queryParameters(loc.search)
const hashParams = queryParameters(loc.hash)
const origin = queryParams.origin || hashParams.origin
const appGuid = queryParams.app_guid || hashParams.app_guid
if (!origin || !appGuid) { return false }

const client = new Client({ origin, appGuid })
const client = new Client({ origin, appGuid, allowOrigin })

if (typeof callback === 'function') {
client.on('app.registered', callback.bind(client))
Expand Down
11 changes: 11 additions & 0 deletions spec/client_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,17 @@ describe('Client', () => {
expect(ACTUAL_ERROR_MSG).to.equal(EXPECTED_ERROR_MSG)
})
})

it('does not clear the iframe and append an error msg when allowOrigin is true', () => {
const validOriginClient = new Client({
origin: 'https://hostmapped.com',
appGuid: 'appGuid',
source: source,
allowOrigin: true
})

expect(validOriginClient).to.exist()
})
})

describe('initialisation', () => {
Expand Down