Skip to content

Commit

Permalink
fix: only fetch pathname to fix url matching issue (#38)
Browse files Browse the repository at this point in the history
<!--- Provide a general summary of your changes in the Title above -->

## Description
Fix making request failure caused by the difference between provided url
in doc and the domain serving on webpage.
<!--- Describe your changes in detail -->
![Screenshot 2024-07-24 at 8 43
32 AM](https://github.com/user-attachments/assets/d1e22a1a-81e6-49e6-9b8b-c7d141ff11e8)

<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)

## Checklist:

<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->

- [x] I have signed the [Adobe Open Source
CLA](https://opensource.adobe.com/cla.html).
- [x] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I have read the **CONTRIBUTING** document.
- [ ] I have added tests to cover my changes.
- [x] All new and existing tests passed.
  • Loading branch information
FentPams authored Jul 24, 2024
1 parent f7c45aa commit c9ff2c0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ function createModificationsHandler(
const url = await getExperienceUrl(ns.config);
let res;
if (url && new URL(url, window.location.origin).pathname !== window.location.pathname) {
res = await replaceInner(url, el);
// eslint-disable-next-line no-await-in-loop
res = await replaceInner(new URL(url, window.location.origin).pathname, el);
} else {
res = url;
}
Expand Down Expand Up @@ -377,7 +378,7 @@ function depluralizeProps(obj, props = []) {
async function getManifestEntriesForCurrentPage(urlString) {
try {
const url = new URL(urlString, window.location.origin);
const response = await fetch(url);
const response = await fetch(url.pathname);
const json = await response.json();
return json.data
.map((entry) => Object.keys(entry).reduce((res, k) => {
Expand Down Expand Up @@ -434,7 +435,7 @@ function watchMutationsAndApplyFragments(
let res;
if (url && new URL(url, window.location.origin).pathname !== window.location.pathname) {
// eslint-disable-next-line no-await-in-loop
res = await replaceInner(url, el, entry.selector);
res = await replaceInner(new URL(url, window.location.origin).pathname, el, entry.selector);
} else {
res = url;
}
Expand Down

0 comments on commit c9ff2c0

Please sign in to comment.