Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

Cannot inject custom js in webapps #124

Closed
mymike00 opened this issue Dec 2, 2018 · 8 comments
Closed

Cannot inject custom js in webapps #124

mymike00 opened this issue Dec 2, 2018 · 8 comments
Assignees

Comments

@mymike00
Copy link
Contributor

mymike00 commented Dec 2, 2018

I have a plain webapp (no qml at all, I have Exec=webapp-container in the .desktop file) and a file called webapp-properties.json which calls a custom script.
the code in this custom script was executed with oxide, but not anymore with morph

@cibersheep
Copy link
Contributor

There's a workaround and is using a qml with a webview and embed the js as a UserScript
In the import area you could:

import QtWebEngine 1.7 as Oxide

And in a Page element

WebContext {
	id: webcontextIF

        userScripts: [
            Oxide.WebEngineScript {
                id: cssinjection
                injectionPoint: WebEngineScript.DocumentCreation
                sourceUrl: Qt.resolvedUrl("js/cssinjection.js")
                worldId: WebEngineScript.MainWorld
            }
	]
}

And the webview:

WebView {
	id: webview

	context: webcontextIF
	url: 'https://whatever'
}

@mymike00
Copy link
Contributor Author

Thanks, I'll try that workaround, but I highly prefer not using qml in simple webapp like mine...

@balcy
Copy link
Collaborator

balcy commented Dec 22, 2018

do you have an example of an app using it ? I've found hints to webapp-properties.json in the source code of morph, but not understood how the properties really work.

@mymike00
Copy link
Contributor Author

my .desktop has

Exec=webapp-container --webappModelSearchPath=. --store-session-cookies --webappUrlPatterns=https?://www.mywebsite.com/* https://www.mywebsite.com/mypath %u

.apparmor is

{
    "template": "ubuntu-webapp",
    "policy_groups": [
        "keep-display-on",
        "networking",
        "webview"
    ],
    "policy_version": 1.3
}

then I have a file called webapp-properties.json

{
    "includes": ["https://www.mywebsite.com:*/*"],
    "name": "ExtendedWebappProperties",
    "scripts": ["myscript.js"],
    "domain":"",
    "homepage":""
}

and obviously a script called myscript.js

@UniversalSuperBox
Copy link
Member

Closed via #140

@Fuseteam
Copy link

This was appearently broken with the removal of oxide

@balcy
Copy link
Collaborator

balcy commented Jan 15, 2022

not with the removal of oxide, but it depended on "Ubuntu.UnityWebApps" which was removed in 18d38c8#diff-0f082207c5919dab491e1030b99f9d8104f6f39d20ecf791924303a33b3bc31e while we moved from Qt 5.9 to Qt 5.12 (the Qt version of the system, not the one of QtWebEngine)

As a replacement we could use a new parameter "--user-scripts=..." to the webapp-container as done in #527

The file webapp-properties.json would then no longer be needed.

in the current example "--user-scripts=myscript.js" would be used.

@Fuseteam
Copy link

Fuseteam commented Jan 16, 2022

ah i see; that sounds like a plan forward yeah, thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants