How to prevent loading of XML-views in UI5? - sapui5

I've paid attention that some implementations of the UI5-based apps prevent of loading XML-views (templates) and I can't get an XML-view via the DevTools' Network tab, e.g.:
https://discovery-center.cloud.sap
https://openui5nightly.hana.ondemand.com
While other implementations load the XML-view and only after that parses it in a browser:
https://openui5nightly.hana.ondemand.com/test-resources/sap/m/demokit/tutorial/walkthrough/37/webapp/test/mockServer.html
How to protect my UI5-app source code and to prevent from the UI5 app loading the XML-view as it appears in IDE?
Is it a matter of the UI5 Tooling configuration?
I know, there is a dedicated step in UI5 Tooling Builder:
(7/8) Running task uglify...
But it looks like, it doesn't prevent from loading XML-views «as is».

Thanks to #Marc for sharing this knowledge! I arrange his info as the proper answer.
The UI5 Tooling proposes an option to minify a codebase of an UI5 app. However, it's still possible to reverse engineer the minified version and to download the original XML-templates with the help of UI5 Diagnostic Tools:
Press Ctrl + Shift + Alt + S, a UI5 Diagnostic Tools pop up should rise up
Go to Control Tree section
Choose the desired view, on the right side of the popup, click on the Export tab
Choose the desired format for exporting: Export to XML or Export to HTML.
P.S. Perhaps worth pointing out that it's possible to prevent activating UI5 Tooling by setting in the HTML bootstrap script the productive-flag to true:
<script type = "text/javascript">
window["sap-ui-config"] = {
"productive" : true
};
</script>
It might complicate a little reverse engineering of an UI5 application.

Related

UI5 parameters: data-sap-ui-xx-waitfortheme and data-sap-ui-xx-componentpreload

The UI5 HTML-bootstrapper has two parameters which I don't really understand:
data-sap-ui-xx-componentpreload
data-sap-ui-xx-waitfortheme
I've checked the official documentation and didn't get some straightforward description.
My questions:
When should I use data-sap-ui-xx-componentpreload and what are its benefits?
When should I use data-sap-ui-xx-waitfortheme and what are its benefits?
⚠️ First things first ...
xx- options are experimental. They may be removed in future UI5 versions or their behavior may change in an incompatible way.
Option sap-ui-xx-componentPreload
By default, UI5 requests the app bundle Component-preload.js automatically when creating ComponentContainer (e.g. via data-sap-ui-oninit="module:sap/ui/core/ComponentSupport").
The bundle is generated by UI5 tooling for deployment so that users finally use the optimized version of the app. Therefore, avoid shipping the standalone app with data-sap-ui-xx-componentpreload in index.html! Otherwise, users will end up using unnecessarily the unminified, unbundled developer version of the app.
Options in index.html (data-sap-ui-*) don't affect typical Fiori launchpad (FLP) apps as FLP uses its own HTML page.
Using sap-ui-xx-componentPreload makes only sense for previewing, testing, or demo scenarios where there is no Node.js environment (unable to use UI5 tooling) so that 404-errors can be avoided. SAP Web IDE, for example, used to append the option sap-ui-xx-componentPreload=off in the URL so that the preview runs without the 404-error.
Values
async or sync by default depending on the sap-ui-preload / sap-ui-async settings.
off to load Component.js instead of Component-preload.js despite having a ComponentContainer.
Option sap-ui-xx-waitForTheme
The xx-waitForTheme option helps to avoid FOUC (Flash Of Unstyled Content) and, in some cases, to reduce sync XHRs. The option tells the app to postpone certain tasks until the theme has been loaded and applied.
Values (since UI5 1.63)
init waits for the theme → executes Core's init handler (attachInit(fn)) → renders the app.
Use this if some controls try to access theme-dependent parameters via sap/ui/core/theming/Parameters.get synchronously (deprecated) too soon.
rendering (formerly true until 1.62) executes Core's init handler first → waits for the theme → initializes the rendering.
If there is no value set, Core's init and initial rendering are executed immediately without waiting for the theme → FOUC.
For more options and information, see Configuration Options and URL Parameters and its parent topics.

Bootstrapping ushell_abap for variant persistence

I have a FIORI application (lunched from launchpad) in which I am using unified shell to persist variants.
In my index.html, I first bootstrap the ushell_abap and then ui bootstrap like this
<script id="sap-ushell-bootstrap" src="https://sapui5.hana.ondemand.com/1.90.0/resources/sap/ushell_abap/bootstrap/abap.js"></script>
<script id="sap-ui-bootstrap" src="https://sapui5.hana.ondemand.com/1.90.0/resources/sap-ui-core.js"
data-sap-ui-libs="sap.ushell, sap.collaboration, sap.m, sap.ui.layout, sap.ui.ux3"
data-sap-ui-theme="sap_belize"
data-sap-ui-resourceroots='{"cvg.wallapp": "./"}'
data-sap-ui-compatVersion="edge"
data-sap-ui-async="true"
data-sap-ui-frameOptions="trusted"
data-sap-ui-bindingSyntax="complex"
data-sap-ui-oninit="module:sap/ui/core/ComponentSupport">
</script>
My app works fine, including variant persistence when running in localhost.
I now deploy the APP to my Fiori server and the bootstrapping process falls apart.
It completely fails to load my theme and associated styling (no custom styling just using the belize theme).
In the console I get the following errors:
includeStylesheet-dbg.js:77 GET https://xxxx:yyyy/sap/public/bc/themes/~client-810/~cache-Bo-MdJE9H9k-CMXXsBrbgsL9ZXQ/UI5/sap/suite/ui/commons/themes/Fiori_LP_Home_Theme/library.css net::ERR_ABORTED 404 (Not found)
One or more parameters could not be found. - sap.ui.core.theming.Parameters
As soon as I remove the bootstrapping of ushell_abap everything works (except the persistence of variants of course).
I have exhausted google searches and reading through the ushell documentation here https://sapui5.hana.ondemand.com/sdk/#/api/sap.ushell
Anyone with an idea on why bootstrapping is failing when truing to use ushell_abap ?
The main issue here was that the app was using a different version of the css libraries than the bootstrap libraries which caused errors (in this case core had new elements in css styling not available in the old css library for core).
If your APP is set up as a standalone APP as explained by Benedikt Kromer and you bootstrap to a specific sapui5 version in the index.html, you can force the app to use the same version css libraries by applying the style to the core on init of the main app.
In on init I just added:
sap.ui.getCore().applyTheme("sap_belize");
This forced the app to load css libraries from the same version I used to bootstrap.
You can see this by watching the network tab in developer tools.
I think you missed one key aspect of the launchpad.
"launched from launchpad" could mean:
It is opening a new tab - standalone -> no need to mention launchpad in the question.
Staying in the same tab - standard/desired setup.
If (1) and you try to load the launchpad theme in your 1.90.0 app. Make sure the ui5 version match exactly.
"parameters could not be found" Could indicate your Theme was create for an older UI5 version.
Possible solutions:
You could generate a theme, matching the standalone ui5 version upload it into an own BSP.
You can ignore the error, there may be some
ui-glitches.
In any case 404 errors indicate also that you didn't link the theme correct in the first place.
If (2), then your index.html is never called. UI5 is starting from the component.js. Hence all your bootstrapping there dosen't count.
In this case index.html is only the playground for local development.
For the shell, this is already in place. I'm not sure why you want to load it again.

Material UI Tabs not rendering properly on server

I am having a problem using the "Tabs" component: https://material-ui.com/components/tabs/ In fact, when developing locally, the rendering of the component is fine. But pushing to the server, it looks weird (with differences in the borders on each side of the bar).
Moreover: when refreshing the page in which it has been embedded or browsing manually to this page, the whole template is broken all of a sudden!
I tried generating a build folder locally and launching the page from that build, and fell back on the same problem.
Thank you in advance for your help
From your description, I saw that your "build" is not work even in local development. That's mean it should not work on the production, of course.
The thing is, what is your actual "build" action? Depends on what library/framework you use, but basically with Material-UI, most popular problem comes from not load some CSS before using it's components.
Please read here first: https://material-ui.com/guides/server-rendering/#server-rendering
Just in case you use Gatsby, read here: https://www.gatsbyjs.org/packages/gatsby-plugin-material-ui/.
I'm using Gatsby and use this following config to fix some CSS issues.
stylesProvider: {
injectFirst: true,
}
Hope this help.

How to see injected scripts in Chrome Developer tools

I am injecting a partial into a page using $().html(content). Part of the partial is JavaScript code in an inline script block I need to inspect. When I look in the Sources tab in the Chrome Developer Tools it doesn't show the injected content. All it shows is the original source.
Is there a way to gain access to the JavaScript?
Update
I am using Google Chrome 21.0.1180.77 but I also have Google Chrome Canary installed.
I don't have a Sources tab (Elements, Resources, Network, Scripts, Timeline, Profiles, Audits, Console).
The Elements tab always reflects the current state of the DOM, so it will show any injected scripts. EDIT: This appears to be wrong.
There's a Chrome issue about this: http://code.google.com/p/chromium/issues/detail?id=95352
You can add a specially formed comment to the injected JavaScript code, and it will then show up in the Scripts tab (but it still doesn't show up in the Elements tab, for whatever reason):
//# sourceUrl=whatever.js
How to see injected snippets:
In order for injected code to be visible, you will need to add a sourceURL comment to the top of the evaluated script, like one of the following:
//# sourceURL=//domain/file.js
//# sourceURL=http://domain/file.js
//# sourceURL=https://domain/file.js
//# sourceURL=//domain/file
Note, that without the // hinting at the protocol and some domain immediately following, then the injected snippet will not show up under sources by default.
How to see injected snippets without a protocol and domain:
Continuing, with just a file name, like so:
//# sourceURL=file.js
You will have to change the source settings by unchecking Group by folder. See image.

chrome cache removal for single files

recently I had to remove my entire cache to be able to view a webpage I was working on. This is fine I guess but it could be improved by removing specific pages from the cache.
the chrome.browsingData.remove, seemingly has no option for indicating individual pages for removal. I was wondering if this could be done externally, but I am not familiar with the chromium code. I was also wondering if there are any planned changes to the chrome.browsingData.remove implementation.
Many thanks
To remove a single file cache enter its URL into browser and do hard refresh.
If you are working on a webpage and wish to avoid caching (btw, it's recommended! :) You can do it today in Chrome DevTools.
Go to Settings (the icon in the bottom-right corner) and click on it.
Then, you will have an option 'disable cache' - mark it and you done.
Just don't forget to return this state when you done working as chrome will be faster with its caching schema.
Edit 10/Feb/2022: Access the remote dev tools documentation for a whole suit of tools available to override cached files while developing:
https://developer.chrome.com/docs/devtools/storage/cache/
If you are attempting to clear HTTP cached data, which was the original question in the post, then the network log is where it is possible. the guide for that is here:
https://developer.chrome.com/docs/devtools/network/#load
First find the file then release its cacged content by right clicking:
https://developer.chrome.com/docs/devtools/network/reference/#clear-cache
To remove all files (not single files) while in Chrome DevTools you should click on the Dev Tools settings then choose
"Disable cache (while DevTools is open)". This was the first option on the page - it is now (as of Chrome 103 in 2022) under network in Preferences.
Note that these settings are not the main Chrome settings, but are specific to Dev Tools.
You can reach DevTools by pressing F12 while on a web page you want to debug or by pressing Ctrl-Shift-I.
Edited 28 July 2022
If you're building the page dynamically, then during development, you can put a random string at the end of the URL used to load the script.
<script src="path/to/script.js?_=<%=Math.random()%>"></script>
This will cause a cache miss for that file but will use the cache for everything else (subject to cache-control headers and so on). Just remember to remove the parameter before pushing to prod!
UPDATE : 2019, April 20
Lately, I'm working with Chrome browser's inbuilt feature - Overrides. With this feature, we can write code for HTML, CSS, JS, etc directly in the console and see it on the web-page.
Here's a tutorial that might be helpful
Previous Answer :
I'm working with Google Chrome extension Resource Override.
After installing this extension, I'm overriding the resource which I want from the server instead of cache:
STEP #2 : Override the resource which you want fresh from the server:
⭐Important Note - Access the plugin from the developer-console instead of the browser
⭐⭐ I started with this approach but have moved to approach suggested by Lukas Greblikas in the answer above.
Good Luck...