Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Readers > Kobo Reader

Notices

Reply
 
Thread Tools Search this Thread
Old 07-13-2023, 10:43 AM   #1
laverdure
Junior Member
laverdure began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Feb 2023
Device: kobo h2o
Angry epub3 javascript in Kobo

Hello
I am trying to develo a stupid epub, but a problem arised I cannot solve.
May be someone faced it.

I composed an epub3 using Sigil, with a single HTML page, like this :

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
<head>
<title></title>
<script type="text/javascript">
function myFun(k) {
this.item = k;
}
</script>
</head>

<body>
<div id="number_one">
<script type="text/javascript">
const c = new myFun("test");
document.getElementById("number_one").innerHTML = c.item;
</script>
</div>
</body>
</html>

it works fine on any reader I checked, and also on Kobo devices (Aura and Libra).

If I try to use an external file for the function, like this:

xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
<head>
<title></title>
<script type="text/javascript" src="../Misc/Script0001.js"></script>
</head>

<body>
<div id="number_one">
<script type="text/javascript">
const c = new myFun(" test 01 : from external file");
document.getElementById("number_one").innerHTML = c.item;
</script>
</div>
</body>
</html>

and script Script0001.js :

function myFun(k) {
this.item = k;
}

it works on Thorium, on Adobe Digital, on Sigil previewer but DON'T work on Kobo.

Of course I checked opf, mimetype, etc, etc.
I never got errors, epub checkers say it's fine, but no way.
Could someone help me?
Thanks a lot
laverdure is offline   Reply With Quote
Old 07-13-2023, 12:26 PM   #2
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 35,513
Karma: 145557716
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Forma, Clara HD, Lenovo M8 FHD, Paperwhite 4, Tolino epos
The question that comes to mind is if you sent it to your Kobo as a .kepub.epub to trigger the WebKit based renderer. If you send it as an epub, you will use the Adobe RMSDK renderer which is more limited on what it will accept.
DNSB is offline   Reply With Quote
Advert
Old 07-14-2023, 02:34 AM   #3
laverdure
Junior Member
laverdure began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Feb 2023
Device: kobo h2o
Thanks for your answer.
I forgot to state that I made both the tryes.
I used 3 or 4 different tools to translate in kepub (calibre, kepubify, etc.), and the result was always the same of epub: no way!
laverdure is offline   Reply With Quote
Old 07-15-2023, 01:19 AM   #4
chrisridd
Guru
chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.
 
chrisridd's Avatar
 
Posts: 929
Karma: 2146660
Join Date: Nov 2011
Location: London, UK
Device: Kobo Aura, Kobo Aura ONE, PocketBook InkPad Color 3
Shouldn't your second test use:

Quote:
<script type="text/javascript" src="../Misc/Script0001.js" />
as this is XML and <script> is an empty element?

Is Script0001.js in the manifest? If you're using Sigil I'd expect it to keeping that up-to-date.
chrisridd is offline   Reply With Quote
Old 07-15-2023, 06:25 AM   #5
laverdure
Junior Member
laverdure began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Feb 2023
Device: kobo h2o
Yes, the file is in the manifest.
I didn’t understand where I should use that script row, sorry.
laverdure is offline   Reply With Quote
Advert
Old 07-17-2023, 02:48 AM   #6
laverdure
Junior Member
laverdure began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Feb 2023
Device: kobo h2o
Hi Chrisridd
I finally got what you said, and I made a try, but the result didn't change.
Thank you for the correction.
laverdure is offline   Reply With Quote
Old 07-17-2023, 03:44 AM   #7
chrisridd
Guru
chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.
 
chrisridd's Avatar
 
Posts: 929
Karma: 2146660
Join Date: Nov 2011
Location: London, UK
Device: Kobo Aura, Kobo Aura ONE, PocketBook InkPad Color 3
Kobo's a bit ambiguous about their Javascript support on e-ink.

Here it says there's limited support: https://github.com/kobolabs/epub-spe...script-support

But here it says it isn't supported at all: https://github.com/kobolabs/epub-spec#support-grid
chrisridd is offline   Reply With Quote
Old 07-17-2023, 06:36 AM   #8
laverdure
Junior Member
laverdure began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Feb 2023
Device: kobo h2o
Yes, I read that document.
As you can see from my little test, it seems than javascript is supported and working, but it is not if functions are in external files.
I can't undenrstand, external files for fonts and styles are read correctly, so external files js should be read as well...
laverdure is offline   Reply With Quote
Old 07-17-2023, 08:06 AM   #9
Quoth
the rook, bossing Never.
Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.
 
Quoth's Avatar
 
Posts: 11,173
Karma: 85874891
Join Date: Jun 2017
Location: Ireland
Device: All 4 Kinds: epub eink, Kindle, android eink, NxtPaper11
Quote:
Originally Posted by laverdure View Post
I can't undenrstand, external files for fonts and styles are read correctly, so external files js should be read as well...
JS is very dangerous compared to fonts and styles. It's a good decision that separate files are not supported and a bad one that an ereader supports javascript at all. At the least there should be an on /off setting that by default is off.
Really only non-ereader apps should execute programs.
Quoth is offline   Reply With Quote
Old 07-17-2023, 10:16 AM   #10
laverdure
Junior Member
laverdure began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Feb 2023
Device: kobo h2o
Thumbs up

If someone is interested, I found a way for executing javascript from extern files.
Don't ask me why or what, but I saw that if the epub contains MINIFIED js files, it works correctly on Kobo Aura, Kobo Touch and Kobo Libra.
I made some test on the same epub I posted at the beginning, and on some other file, and the result is OK: if js file is minified it works on Kobo.

Last edited by laverdure; 07-17-2023 at 10:17 AM. Reason: Missing info
laverdure is offline   Reply With Quote
Old 07-19-2023, 11:02 AM   #11
chrisridd
Guru
chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.chrisridd ought to be getting tired of karma fortunes by now.
 
chrisridd's Avatar
 
Posts: 929
Karma: 2146660
Join Date: Nov 2011
Location: London, UK
Device: Kobo Aura, Kobo Aura ONE, PocketBook InkPad Color 3
Quote:
Originally Posted by laverdure View Post
if js file is minified it works on Kobo.
Perhaps the file was slightly malformed originally, and minifying has handled that and produced valid output? I have no idea otherwise!
chrisridd is offline   Reply With Quote
Reply

Tags
epub3, javascript, kobo


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
EPUB3: resize SVG in javascript fbrzvnrnd ePub 32 02-03-2017 04:39 AM
ePub3: localStorage/JavaScript/RTL support Doitsu ePub 7 06-02-2015 06:55 AM
Is there any android epub reader supporting epub3 with audio/video/javascript? happycoding Android Developer's Corner 10 07-29-2014 11:16 AM
Create a javascript quizz for Epub3 in Sigil BertrandThibaut Sigil 3 01-26-2014 09:04 AM
JAVASCRIPT support in ePub2/ePub3 Raja1205 ePub 7 09-03-2012 06:48 AM


All times are GMT -4. The time now is 01:27 PM.


MobileRead.com is a privately owned, operated and funded community.