Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kesandal's avatar

Raw javascript isn't working correctly when insertet into vue root component

Hi there,

I'm creating a Laravel 9 application with Vue 2.

Currently I'm trying to implement a verification service (sumsub) into my application. However, I'm facing problems which seem to be related to vue.

Below is the minimum example.

blade-file:

<!DOCTYPE html>
<html>
    <head>
        @meta_tags
        <script src="/js/sns-websdk-builder.js"></script>
    </head>
    <body>
        <div id="app">
            // CODE FROM BY DESCRIPTION BELOW GOES HERE
        </div>
        @meta_tags('footer')
    </body>
</html>

minimum code to implement to get the verification service working:

<div id="sumsub-websdk-container"></div>
<script type="application/javascript">
	function launchWebSdk(accessToken, applicantEmail, applicantPhone) {
		let snsWebSdkInstance = snsWebSdk.init(
			accessToken,
			() => this.getNewAccessToken()
		)
			.withConf({
				lang: 'en',
				email: applicantEmail,
				phone: applicantPhone,
				i18n: {"document":{"subTitles":{"IDENTITY": "Upload a document that proves your identity"}}},
				onMessage: (type, payload) => {
					console.log('WebSDK onMessage', type, payload)
				},
				uiConf: {
					customCssStr: ""
				},
				onError: (error) => {
					console.error('WebSDK onError', error)
				},
			})
			.withOptions({ addViewportTag: false, adaptIframeHeight: true})
			.on('stepCompleted', (payload) => {
				console.log('stepCompleted', payload)
			})
			.on('onError', (error) => {
				console.log('onError', payload)
			})
			.onMessage((type, payload) => {
				console.log('onMessage', type, payload)
			})
			.build();
		snsWebSdkInstance.launch('#sumsub-websdk-container')
	}

	function getNewAccessToken() {
		return Promise.resolve("1234")
	}

	launchWebSdk("1234")
</script>

Observations

If I put the JS code into the main vue container (<div id="app"></div>) the page loads, but nothing happens.

  • No errors in console.
  • Network tab in browser: websdk.html?_=id_71354100 <== this comes from sumsub | Status: canceled

But the JavaScript-code seems to get executed. Because after loading the page and examining the source

<div id="sumsub-websdk-container"></div>

turns into:

<iframe width="100%" scrolling="no" allow="camera; microphone" frameborder="0" src="https://api.sumsub.com/idensic/websdk.html?_=id_7577300"></iframe>

It looks like vue is blocking loading the src from the iframe.

If I change the ID of the root component <div id="app"></div> to app2 vue complains (browser console) but the verification window appears - as it should.

If I put the whole JS code together with <div id="sumsub-websdk-container"></div> into a vue component everything works fine too.

Can anyone give me a hint please how to solve this problem? Later I would like to put the whole "verification part" into a blade component, however before doing this I would like to solve this "main" problem.

0 likes
1 reply
rodrigo.pedra's avatar

Are you adding both the div and the script tag inside the div element you are rendering your Vue app?

If so, the problem is this. Vue doesn't allow script tags inside templates. And depending on how your app is set up it will try to parse the contents of the div you render your app as the root's element template.

Just leave the div where you want your vue app rendered empty (`") and add this third-party code after this div, not inside it.

Or better yet, properly load this third-party code into a Vue component.

I wrote a more detailed explanation on this answer from a year ago:

https://laracasts.com/discuss/channels/laravel/how-do-you-include-the-code-or-script-in-nuxt-js-with-the-script-tags?page=1&replyId=660825

1 like

Please or to participate in this conversation.