J4 Issue ?
avatar brianteeman
brianteeman
28 Jul 2019

Steps to reproduce the issue

On a clean install try to install the "Testing Sample Data"

Expected result

Sample data completes all 8 steps successfully

Actual result

Sample data "hangs" after step 7 and console shows the following error


VM701:1 Uncaught SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at onSuccess (sampledata-process.min.js?988a0f8a06606e444ef81cacee8fef3d:1)
    at XMLHttpRequest.c.onreadystatechange (core.min.js?988a0f8a06606e444ef81cacee8fef3d:1)
onSuccess @ sampledata-process.min.js?988a0f8a06606e444ef81cacee8fef3d:1
c.onreadystatechange @ core.min.js?988a0f8a06606e444ef81cacee8fef3d:1
XMLHttpRequest.send (async)
a.request @ core.min.js?988a0f8a06606e444ef81cacee8fef3d:1
c.sampledataAjax @ sampledata-process.min.js?988a0f8a06606e444ef81cacee8fef3d:1
onSuccess @ sampledata-process.min.js?988a0f8a06606e444ef81cacee8fef3d:1
c.onreadystatechange @ core.min.js?988a0f8a06606e444ef81cacee8fef3d:1
XMLHttpRequest.send (async)
a.request @ core.min.js?988a0f8a06606e444ef81cacee8fef3d:1
c.sampledataAjax @ sampledata-process.min.js?988a0f8a06606e444ef81cacee8fef3d:1
onSuccess @ sampledata-process.min.js?988a0f8a06606e444ef81cacee8fef3d:1
c.onreadystatechange @ core.min.js?988a0f8a06606e444ef81cacee8fef3d:1
XMLHttpRequest.send (async)
a.request @ core.min.js?988a0f8a06606e444ef81cacee8fef3d:1
c.sampledataAjax @ sampledata-process.min.js?988a0f8a06606e444ef81cacee8fef3d:1
onSuccess @ sampledata-process.min.js?988a0f8a06606e444ef81cacee8fef3d:1
c.onreadystatechange @ core.min.js?988a0f8a06606e444ef81cacee8fef3d:1

avatar brianteeman brianteeman - open - 28 Jul 2019
avatar joomla-cms-bot joomla-cms-bot - change - 28 Jul 2019
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 28 Jul 2019
avatar franz-wohlkoenig franz-wohlkoenig - change - 28 Jul 2019
Labels Added: J4 Issue
avatar franz-wohlkoenig franz-wohlkoenig - labeled - 28 Jul 2019
avatar richard67
richard67 - comment - 28 Jul 2019

Blog sample data stops after step 2 of 4 with

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
onSuccess media/mod_sampledata/js/sampledata-process.min.js?2968200e5b0c6143dac6a234ae0ea7d1:1
onreadystatechange media/system/js/core.min.js?2968200e5b0c6143dac6a234ae0ea7d1:1

avatar richard67
richard67 - comment - 28 Jul 2019

Multilingual sample data works.

avatar franz-wohlkoenig franz-wohlkoenig - change - 28 Jul 2019
Status New Discussion
avatar dgrammatiko
dgrammatiko - comment - 28 Jul 2019

VM701:1 Uncaught SyntaxError: Unexpected token < in JSON at position 0

It’s obvious that the response is not json, probably because of a php error. A try/catch on the parsing will eliminate the console error (and should be done) but also the root of the problem should be fixed (eg php side)

avatar Bakual
Bakual - comment - 28 Jul 2019

Dimitri is right. The source is most likely a PHP error. You should see it in the log file.
It may only be a notice, which when displayed may break the JSON response. XDebug also doesn't help here with its HTML output :)

On the JS things I can't help but it certainly should somehow catch such errors and give an appropriate generic message (eg "malformed response" or along that line).

avatar richard67
richard67 - comment - 28 Jul 2019

PHP Notice: Undefined property: Joomla\CMS\Table\Module::$element in /home/richard/lamp/public_html/joomla-cms-4.0-dev/plugins/system/httpheaders/httpheaders.php on line 201

A lot of them come when installing testing sample data. I think the same also came when installing blog sample data before. Interesting that it did not come with multilanguage sample data.

avatar richard67
richard67 - comment - 28 Jul 2019

But there were no PHP errors, only these notices.

avatar brianteeman
brianteeman - comment - 28 Jul 2019

Disabling the httpheaders plugin resolves the problem :(

avatar brianteeman brianteeman - change - 28 Jul 2019
Title
[4.0] Test data plugin js errors
[4.0] httpHeaders plugin breaks sample data plugins
avatar brianteeman brianteeman - edited - 28 Jul 2019
avatar richard67
richard67 - comment - 28 Jul 2019

Ping @zero-24 Any idea?

avatar richard67
richard67 - comment - 28 Jul 2019

And who can care for the js part?

dgrammatiko:

A try/catch on the parsing will eliminate the console error (and should be done)

Bakual:

On the JS things I can't help but it certainly should somehow catch such errors and give an appropriate generic message (eg "malformed response" or along that line).

avatar dgrammatiko
dgrammatiko - comment - 28 Jul 2019

@richard67 the change is really simple follow my comment on #23936 (comment)
basically, the onSuccess needs to look like this:

            onSuccess: (resp) => {
              let responnse;
              try {
                response = JSON.parse(resp);
              } catch (error) {
                throw new Error('Failed to parse JSON')
              }

Also this patch needs to be applied to all the ajaxy scripts that deal with json responses!!!

avatar zero-24
zero-24 - comment - 29 Jul 2019

Disabling the httpheaders plugin resolves the problem :(

Please check and share the browser console message when this error happens (from chrome when possible).
Please also tell us which headers you have enabled and with what settings.

Thanks.

avatar zero-24
zero-24 - comment - 29 Jul 2019

PHP Notice: Undefined property: Joomla\CMS\Table\Module::$element in /home/richard/lamp/public_html/joomla-cms-4.0-dev/plugins/system/httpheaders/httpheaders.php on line 201

A lot of them come when installing testing sample data. I think the same also came when installing blog sample data before. Interesting that it did not come with multilanguage sample data.

@richard67 that error message should have nothing to-do with sample data hopefully. As this line should only be executed when we have an onExtensionAfterSave. But please share a dump of the event object ($event) just before the error comes up. Or can you reproduce the error message?

avatar brianteeman
brianteeman - comment - 29 Jul 2019

Please check and share the browser console message when this error happens (from chrome when possible).

Already in the first post

Please also tell us which headers you have enabled and with what settings.

Clean install so whatever the defaults are

avatar zero-24
zero-24 - comment - 29 Jul 2019

Already in the first post

That is the only message?

Clean install so whatever the defaults are

The only defaults on a clean install are x-frame-options, xss-protection, referrer-policy, (x-content-type-options).

Where I don't expect issues from x-frame-options and referrer-policy.
x-content-type-options is now enforced from the htaccess file so the setting has no affect.

So the only thing could be xss-protection can you try to disable that instead of completly disable the plugin?

avatar SharkyKZ
SharkyKZ - comment - 29 Jul 2019

Test PR #25739 please.

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 29 Jul 2019

Closed as having Pull Request #25739

avatar franz-wohlkoenig franz-wohlkoenig - change - 29 Jul 2019
Status Discussion Closed
Closed_Date 0000-00-00 00:00:00 2019-07-29 11:30:09
Closed_By franz-wohlkoenig
avatar franz-wohlkoenig franz-wohlkoenig - close - 29 Jul 2019
avatar brianteeman
brianteeman - comment - 29 Jul 2019

Thanks @SharkyKZ for correctly identifying that the error was in the php

avatar dgrammatiko
dgrammatiko - comment - 29 Jul 2019

You never fixed the client side problem here so why was this closed?

Add a Comment

Login with GitHub to post a comment